Hey! So I'm trying to make a menu that tweens up and down when you click a button. Only problem is the BoolValue that controls if the tween goes up or down doesn't change, It stays on false even though I've changed it in the script. Here is the code:
Open = script.Parent.Open Open.Value = false debounce = false script.Parent.MouseButton1Click:Connect(function() if Open.Value == false then if debounce == false then debounce = true Open.Value = true script.Parent.Text = "Close" script.Parent.Parent.Main:TweenPosition(UDim2.new(0.2,0,0.2,0)) wait(3) debounce = false elseif debounce == true then print("Debounce is true cant do that") elseif Open.Value == true then Open.Value = false if debounce == false then debounce = true script.Parent.Text = "Menu" script.Parent.Parent.Main:TweenPosition(UDim2.new(0.2,0,-1,0)) wait(3) debounce = false elseif debounce == true then print("Debounce is true cant do that") end end end end)
If somebody could help me with my problem that would be greatly appreciated! Thanks!
For line 7 if then statement doesn’t change open.Value to false. The next time you go through the function you can’t do anything. The elseifs (line 17 and 20) are alternates to the line 9 if then statement, not line 7 if then statement. To resolve this, put the elseifs after an end
I assume it's because your changing the value through a local script. LocalScripts only happen on the client, not the server.
This is how I would do it. You don't really even need those bool values, just variables.
local open = false local debounce = true local cooldown = 3 script.Parent.Activated:Connect(function() --// Activated is the same as MouseButton1Click if open == false and debounce == true then open = true debounce = false script.Parent.Text = "Close" script.Parent.Parent.Main:TweenPosition(UDim2.new(0.2,0,0.2,0),"Out","Quad",1,true) wait(cooldown) debounce = true elseif open == true and debounce == true then open = false debounce = false script.Parent.Text = "Menu" script.Parent.Parent.Main:TweenPosition(UDim2.new(0.2,0,-1,0),"Out","Quad",1,true) wait(cooldown) debounce = true end end)
The ("Out","Quad",1,true)
are Easing Direction (Out), Easing Style (Quad), Time (1), and the Override (true). All the Wiki's that explain how to use everything is below!
I recommend to use EasingDirection
, EasingStyle
, Time
, and Override
to make your GUI look unique. You can use Callback
if you want something to happen whenever the GUI is finished tweening.
Hope this helped!