How To Check If Humanoid Already Contains Accessory?

I have a part that if the player touches, he gets skates added to his shoes. I realized that if the player goes on the part multiple times, he gets multiple shoes, and I tried to stop this using an if statement, but it did not work. This is the script I have now :

local part = script.Parent
local serverStorage = game:GetService("ServerStorage")

local function addSkates(player)
local partParent = player.Parent

local humanoid = partParent:WaitForChild("Humanoid")
local children = humanoid:GetChildren()

if humanoid then
	local leftShoe = serverStorage:WaitForChild("LeftSkate"):Clone()
	local rightShoe = serverStorage:WaitForChild("RightSkate"):Clone()
	local leftShoeOnPlayer = humanoid:FindFirstChild("LeftSkate")
	local rightShoeOnPlayer = humanoid:FindFirstChild("RightSkate")
	if leftShoeOnPlayer or rightShoeOnPlayer then
		print("destroying shoes")




The problem with this script is that it does not remove the duplicates. The idea behind this one was that everytime the player touched the part, it would delete his shoes, if not,it would add shoes, so that he always has one pair of skates. Thanks :smiley:

I’m not sure that accessories would be held in the humanoid, try doing

local rightShoeOnPlayer = humanoid["Parent"]:FindFirstChild("RightSkate")
local leftShoeOnPlayer = humanoid["Parent"]:FindFirstChild("LeftSkate")

or if you have the character already defined you can use that.

1 Like

Yeah I see, that was the problem, I kept thinking the accessories were children of the humanoid,

1 Like

You can also use. Humanoid | Roblox Creator Documentation

1 Like