Hey guys, this script works sometimes, but not always. I have this snippet 3 times in a LocalScript, but sometimes when I join, none of the three doors get removed (when I touch all three) even though I have enough Wins.
workspace:WaitForChild("BallPitDoor").Touched:Connect(function()
if game.Players.LocalPlayer:WaitForChild("leaderstats"):WaitForChild("Wins").Value >= 1 then
workspace.BallPitDoor:Destroy()
end
end)
You can always use prints to troubleshoot your code, like this:
workspace:WaitForChild("BallPitDoor").Touched:Connect(function()
wins = game.Players.LocalPlayer:WaitForChild("leaderstats"):WaitForChild("Wins").Value -- just sets the variable so you only have to set it once
print("Wins = ", wins) -- tells you if your door Touched is firing and the number of Wins there are
-- this also tells you if the next section of code should run
if wins >= 1 then
workspace.BallPitDoor:Destroy()
end
end)
The issue turned out to be a WaitForChild before all of these things that was yielding and preventing the code from reaching, and that WaitForChild was sometimes finishing. My new question is: why does this sometimes yield infinitely?
local wins = player:WaitForChild("leaderstats"):WaitForChild("Wins").Value
(The issue is resolved but I’m still curious)
Edit: it’s not resolved! Still welcoming suggestions.
local wins = player:WaitForChild(“leaderstats”):WaitForChild(“Wins”).Value
This yields until an instance of base class Value (probably an IntValue) named Wins exists in the player’s instance and its value can be read. The only reason this would yield is if Wins didn’t exist yet.
Try following the creation of the Wins instance and see what happens