I want it to remove the player's accessories on a server event
game.ReplicatedStorage.Events.Remove.OnServerEvent:Connect(function(plr) local char = plr.Character for i,v in pairs(char:GetChildren()) do if v.ClassName == "Accessory" then v:Remove() end end end)
This one is quite simple actually. I tested your code and its the name you're using for the remote. When the script is running, it sees the name "Remove"
and interprets it as the function :Remove()
. All you have to do is rename the RemoteEvent.
I also recommend using :Destroy()
over :Remove()
, as it is sets the parent to nil and locks the parent, making it more secure.
Hope this helps! If you have any further questions feel free to comment or look things up on the devforum.
there is a getaccessories thing so you can use also please dont use classname and use IsA
game.ReplicatedStorage.Events.Removes.OnServerEvent:Connect(function(plr) local char = plr.Character for i,v in pairs(char.Humanoid:GetAccessories()) do v:Remove() end end)
The humanoid has its own function called GetAccessories that retrieves all the accessories that the character has. No need to use GetChildren. https://developer.roblox.com/en-us/api-reference/function/Humanoid/GetAccessories
Here's how it could be done:
game.ReplicatedStorage.Events.Remove.OnServerEvent:Connect(function(plr) local char = plr.Character for i,v in pairs(char.Humanoid:GetAccessories()) do v:Destroy() end end)