Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

My checkpoint script for my obby is not really working what it is intended to do, how to fix this?

I am making an obby and have made an script that half of it works and the other one, not so much.

Here is the script:

local debounce1 = false
local StageValue = 0
workspace.Stages.Stage1.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChildOfClass("Humanoid") and not debounce1 then
        StageValue = StageValue + 1

        if StageValue == 1 then
            print("this works")
            local debounce1 = true
        end
    end
end)

local debounce2 = false
workspace.Stages.Stage2.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChildOfClass("Humanoid") and not debounce2 then
        StageValue = StageValue + 1

        if StageValue == 2 then
            print("this does not get printed i dont know why")
            local debounce2 = true
        end
    end
end)

The script does not give an error it just does not work.

1 answer

✓ Accepted answer

You could try this:

local debounce1 = false
local StageValue = 0
local Touched1 = false
local Touched2 = false
workspace.Stages.Stage1.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChildOfClass("Humanoid") and not debounce1 and not Touched1 then
Touched1 = true
        StageValue = StageValue + 1

        if StageValue == 1 then
            print("this works")
            local debounce1 = true
        end
    end
end)

local debounce2 = false
workspace.Stages.Stage2.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChildOfClass("Humanoid") and not debounce2 and not Touched2 then
Touched2 = true
        StageValue = StageValue + 1

        if StageValue == 2 then
            print("this does not get printed i dont know why")
            local debounce2 = true
        end
    end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.