Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

This script is not removing the player's accessories?

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)

3 answers

✓ Accepted answer

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.

3 comments

0

I'll see if it works. Thanks :)

0

Thanks

0

no problem!

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)

2 comments

0

plz upvote me

0

oh i forgot. use v:Destroy() because :remove() is deprecated

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)

1 comment

0

Thanks for telling me that

This discussion is preserved as it was. New answers, comments, and votes are closed.