Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can i detect when the player leaves this part?

Asked by 2 years ago
Edited 2 years ago
Debounce = false
while task.wait() do
    local Zone = workspace:GetPartsInPart(script.Parent)
    for i, v in pairs(Zone) do
        if v.Name == "UpperTorso" and not Debounce then
            Debounce = true
            print("Player detected")    
            wait(2)
            Debounce = false
            return end
        if Debounce == true then
            print("player left")
            wait(2)
            Debounce = false
        end
    end
end

This works normally as a touch script, but i need it to print properly when the player enters and when the player leaves. Any help is appreciated! Edit: Replaced confusing words with more confusing words

1 answer

Log in to vote
0
Answered by 2 years ago

Just solved it lol, i thought "Return" just broke the loop and brought it back to the top. fixed it with a proper break

Ad

Answer this question