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

Why is this open/close gui not working? [TWEEN]

So, I am trying to make a gui open/close with tweening, can someone explain why this is not working? It will open, but it will not close afterwards.

script.Parent.MouseButton1Click:Connect(function()
	local work = false
	if work == false then
		work = true
		script.Parent.Parent:TweenPosition(UDim2.new(0.736, 0,0.304, 0))
		wait(1)
	else
		work = false
		script.Parent.Parent:TweenPosition(UDim2.new(0.932, 0, 0.304, 0))
		wait(1)
	end
end)

This is a local script. Any help will be greatly appreciated.

2 comments

0

I'm not sure how to explain, I don't have a soltion for you but the "if" never notice that "work" changes value. So it never goes to the "else"

0

but it opened after the "if" statement.

1 answer

Make work a script-wide variable.

The issue here is that your variable, work, is being created from inside the function - and thus is never actually true and not up-to-date with the current state of your UI.

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