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")
leftShoeOnPlayer:Destroy()
rightShoeOnPlayer:Destroy()
else
humanoid:AddAccessory(rightShoe)
humanoid:AddAccessory(leftShoe)
end
wait(5)
end
end
part.Touched:Connect(addSkates)
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