So I want to move a player that touches the part by one stage (with debounce). It does move but it moves the player by 2-3 stages with the debounce. Tried searching something similar but nothing matching the same thing.
The script:
local debounce = false
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
wait(0.5)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
debounce = true
player.leaderstats.Stage.Value = player.leaderstats.Stage.Value + 1
player.Character:MoveTo(game.Workspace.Checkpoints:FindFirstChild(player.leaderstats.Stage.Value).Position)
wait(2)
debounce = false
end
end)
local debounce = false
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and debounce == false then
debounce = true
wait(0.5)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
player.leaderstats.Stage.Value = player.leaderstats.Stage.Value + 1
player.Character:MoveTo(game.Workspace.Checkpoints:FindFirstChild(player.leaderstats.Stage.Value).Position)
wait(2)
debounce = false
end
end)
All you needed to do was to add the debounce in your if statement.