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

BoolValue wont change inside of a localscript?

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!

3 comments

0

Instead of “if Open.Value == false then” and the line after that “if debounce == false then”, do “if Open.Value == false and debounce == false then”

0

put 'local' before the Open variable at the top

0

Same with the debounce variable

2 answers

✓ Accepted answer

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

2 comments

0

To show this, after open.Value becomes true, you click. It goes through function. Then it hits the if then statement of line 7, which is the only one for the function. Because Open.Value is true, it can’t go through that if then statement. That if then statement is the only one for then function. The elseifs are the alternates to line 9, which you have to go through the if then statement of line

0

7 to go to it. Therefore, to go to the elseifs you must go to the if then statement of line 7. But since Open.Value has to be false to go through the if then statement of line 7 and Open.Value was turned to true and not turned back, the function doesn’t work.

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.


GUI Tweening

Easing Direction

Easing Style


Hope this helped!

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