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

Make a Wait() reset if the function is executed again?

Asked by 5 years ago
Receptor.Union:GetPropertyChangedSignal("Position"):Connect(function()
    print("reset")
    repeat wait() until Receptor.Parent == workspace
    repeat wait() until game.Players.LocalPlayer.PlayerGui.Menu.Frame.Frame.Visible == false
    print("waiting")
        wait(30)
end)

I have a block that you have to move around, and if it stays in one place for 30 seconds then it will do something else. How can I make this happen?

1 answer

Log in to vote
0
Answered by
DanzLua 2879 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

We create a variable outside of the event function that we can use to check inside the function while we wait those 30 seconds

local position

while Receptor.Parent~=workspace do wait() end

Receptor.Union:GetPropertyChangedSignal("Position"):Connect(function()
    if Receptor.Union.Position==position then return end
    position=Receptor.Union.Position
    local n=0
    repeat n=n+1 wait(1) until n>=30 or position~=Receptor.Union.Position
    if position==Receptor.Union.Position then
        --do stuff
    end
end)

The script above is if it a server script, if it were a localscript, as im assuming since your checking something in the playergui I'd add a check alongside the first if statement like so

local position

while Receptor.Parent~=workspace do wait() end

Receptor.Union:GetPropertyChangedSignal("Position"):Connect(function()
    if Receptor.Union.Position==position and game.Players.LocalPlayer.PlayerGui.Menu.Frame.Frame.Visible == true then return end
    position=Receptor.Union.Position
    local n=0
    repeat n=n+1 wait(1) until n>=30 or position~=Receptor.Union.Position
    if position==Receptor.Union.Position then
        --do stuff
    end
end)
Ad

Answer this question