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

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

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

✓ Accepted answer

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)

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