RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"make an event that gives all players a hat . add detailed comments and instructions"
-- server script (ServerScriptService) -- create a function to give a hat to a player local function giveHat(player) local hatID = 12345678 -- replace with the desired hat ID local hat = Instance.new("Hat") hat.Parent = player.Character local handle = Instance.new("Part") handle.Parent = hat handle.CanCollide = false handle.Transparency = 1 local mesh = Instance.new("SpecialMesh") mesh.Parent = handle mesh.MeshId = "rbxassetid://" .. tostring(hatID) mesh.TextureId = "rbxassetid://" .. tostring(hatID) end -- create an event that triggers when a player joins the game game.Players.PlayerAdded:Connect(function(player) -- wait for the player's character to load player.CharacterAdded:Wait() -- give the hat to the player giveHat(player) end) -- give the hat to all current players for _, player in ipairs(game.Players:GetPlayers()) do if player.Character then giveHat(player) else player.CharacterAdded:Connect(giveHat) end end -- Instructions: 1. Create a new script in ServerScriptService. 2. Copy and paste the code above into the script. 3. Replace the 'hatID' variable with the desired hat ID from the Roblox catalog. 4. Run the game, and all players should receive the hat upon joining.