So, I need to get a hat remover when a player enters a server, but haven't seen to get it working yet. Any tips? My code atm:
local player = game:GetService("Players").LocalPlayer game.Players.PlayerAdded:connect(function() for _, object in pairs(player.Character:GetChildren()) do if object:IsA("Hat") then object:Destroy() end end end)
The character doesn't load instantly, you will need another function to fire when the character is added, doing this also allows you to have them removed each time a player dies. The game.Players.PlayerAdded function is unnecessary as each time any player joins it will try to remove the player's hats. Here's the code you should be using assuming this is a local script:
local player = game.Players.LocalPlayer player.CharacterAdded:connect(function(char) for _,obj in pairs(char:GetChildren()) do if obj:IsA("Hat") then obj:Destroy() end end end)
Instead of having this, you could use a server script in Workspace or ServerScriptService, here's the script you could use for that:
game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(char) for _,obj in pairs(char:GetChildren()) do if obj:IsA("Hat") then obj:Destroy() end end end) end)
If this worked for you and/or helped you please vote up and accept this as the answer!