if workspace:FindFirstChild("Pumpkin") then game.Players.PlayerAdded:Connect(function(player) local Na = player.Name workspace.Pumpkin.Parent = Na end) end
There's 1 accesory named Pumpkin and I want every player to join to wear the pumpkin but I keep getting a error
I usually just make the accessory's parent into StarterCharacterScripts
Humanoid documentation includes a function "AddAccessory" to do just that!
An example would be this:
if workspace:FindFirstChild("Pumpkin") then game.Players.PlayerAdded:Connect(function(player) -- Check if the character exists to prevent a crash if player.Character then local accessory = workspace.Pumpkin -- :Clone() player.Character:WaitForChild("Humanoid"):AddAccessory(accessory) end end) end
or optionally you could do this:
if workspace:FindFirstChild("Pumpkin") then game.Players.PlayerAdded:Connect(function(player) -- Error handling local result,err = pcall(function() local accessory = workspace.Pumpkin -- :Clone() player.Character:WaitForChild("Humanoid"):AddAccessory(accessory) end) if not result then warn(err) -- Display any errors without breaking the code end end) end
You can put the Pumpkin into ServerStorage:
game.Players.PlayerAdded:Connect(function(player) player.Character.Humanoid:AddAccessory(game.ServerStorage.Pumpkin:Clone()) end)
Bad formatting on mobile