Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

This script is not removing the player's accessories?

Asked by 4 years ago

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

Log in to vote
3
Answered by
ArtBlart 533 Moderation Voter
4 years ago

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.

0
I'll see if it works. Thanks :) Justingamer700 114 — 4y
0
Thanks Justingamer700 114 — 4y
0
no problem! ArtBlart 533 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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)
0
plz upvote me ZorbaTheGreatGreek 59 — 4y
0
oh i forgot. use v:Destroy() because :remove() is deprecated ZorbaTheGreatGreek 59 — 4y
Log in to vote
0
Answered by 4 years ago

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)
0
Thanks for telling me that Justingamer700 114 — 4y

Answer this question