In my game, if the player steps on a certain pad they will be granted +10 coins. Here is the script I'm using:
script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then wait(0.4) game.Players:FindFirstChild(hit.Parent.Name).moneystats.Coins.Value += 10 wait (5) end end)
This script works, but it has an issue. If it registers both legs landing on the pad at once, (such as when a player jumps on to it), it will execute the script twice and award 20 coins. I tried to fix this by awarding the coins only if the left leg touched the pad. That way, the script will not be triggered twice if both legs touch at the same time. To do this, I used the above script but changed ("Humanoid") to ("LeftLeg"):
script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("LeftLeg") then wait(0.4) game.Players:FindFirstChild(hit.Parent.Name).moneystats.Coins.Value += 10 wait (5) end end)
However, this script resulted in no coins being awarded. Does anyone know how to fix the script so the coins will be awarded only when the left leg touches the pad?
That's because "LeftLeg" is not part of the Body but "Left Leg" is the correct name.
script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Left Leg") then wait(0.4) game.Players:FindFirstChild(hit.Parent.Name).moneystats.Coins.Value += 10 wait (5) end end)