Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

BoolValue wont change inside of a localscript?

Asked by 4 years ago

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!

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” Geobloxia 251 — 4y
0
put 'local' before the Open variable at the top rhettsmith6537 109 — 4y
0
Same with the debounce variable rhettsmith6537 109 — 4y

2 answers

Log in to vote
0
Answered by
Geobloxia 251 Moderation Voter
4 years ago
Edited 4 years ago

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

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 Geobloxia 251 — 4y
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. Geobloxia 251 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

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!

Answer this question