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

How would I use :wait() to wait until a ScreenGui's position is whatever?

The title really says it all.

I'm building an AdminGui, I'm just adding the 10%. I want an ImageButton to rotate, and it does, but while the GUI is being tweened, you can click the button, rotate it, and cause the GUI to break temporarily. I have a debounce in place, but it's not effective because it deactivates immediately after clicking. So, I need it to deactivate the debounce after the GUI has been tweened.

So, "How would I use :wait() to wait until a ScreenGui's position is whatever?".

1 answer

✓ Accepted answer

It's a simple do while function that takes rotate into account:

rotate = false --Debounce
function waitUntil(ed,gui) --Create a function for waiting until a GUI is in the right spot
	if rotate == false then --If rotating is false
		repeat wait() gui.Rotation = 0 rotate = false until gui.Position == ed --force it to not rotate until the movement is finished
		return true --return true
	else 
		repeat wait() until rotate == false --if rotate is true wait until rotate is false
		waitUntil(end,gui) --call the function
		return --return nil
	end
end

function rotate(gui) --Create a function for rotating
	rotate = true --set rotate to true
	for i=1,90 do -- or how many degrees you want to rotate it
		if rotate == false then break end --if the tween started stop
		gui.Rotation = gui.Rotation+1 --rotate
		game:GetService("RunService").RenderStepped:wait() --wait one frame
	end
	rotate = false --set rotate to false
end

3 comments

0

I got it fixed, but not with what you gave me; I didn't understand it, and I don't want to use something I don't understand. What I did was wait 2.5 seconds, which is the amount of time the GUI is given to tween itself, and it works seamlessly. But, I do that you very much for replying and trying to help me.

0

You didn't even call the functions...

0

Narrev, You don't call the functions in example code. It's not going to run anyways.

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