I made a script so that when a player enters, its hats will be deleted. Here is the script:
game.Players.PlayerAdded:Connect(function(player) local char = player.Character if char then local count = char:GetChildren() for i = 1, #count do if (count[i].className == "Accessory") then count[i]:Destroy() end end end end)
Also, click me to see where the script is in.
Hope someone can help me fix the problem!
game.Players.PlayerAdded:Connect(function(player) player.CharacterAppearanceLoaded:Connect(function(char) for i, v in pairs(char:GetChildren()) do if v:IsA("Accessory") then v:Destroy() end end end) end)
Wiki links : 1. https://developer.roblox.com/api-reference/event/Player/CharacterAppearanceLoaded 2. https://developer.roblox.com/api-reference/function/Instance/IsA
When a player is added the char variable is defined very quickly, not allowing the character to load. So the hats remover script part doesn't execute.
You should use the player.CharacterAdded function which will be fired each time a player dies.
The fixed script would be
game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(char) local count = char:GetChildren() for i = 1, #count do if (count[i].className == "Accessory") then count[i]:Destroy() end end end) end)
If this answered your question then don't forget to click the Accept Answer button.