Ad
Log in to vote
0

if statement not working properly?

Asked by 7 months ago

I have this script that is supposed to make the player's gui visible if playing is equal to false and make it not visible if playing is equal to true but for some reason the script constantly outputs saying "playing = false" even when I make the playing value equal true? The playing value is a boolean value in a folder in the workspace

while wait() do
    if game.Workspace.Values.Playing.Value == false then
        print("playing = false")
        script.Parent.Visible = true
    else if game.Workspace.Values.Playing.Value == true then
                print("playing = true")
            script.Parent.Visible = false
        end
    end
end

Please help!

0
Appropriately, it's "elseif". Ziffixture 6785 — 7mo

1 answer

Log in to vote
3
Answered by 7 months ago

Here's my code, a good explanation in the notes as well.

--[[
It is suggested that you use "workspace" instead of "game.Workspace".
]]

while wait() do
    --[[
    It's good to use pcall (protect-call) so that you don't run into an error.
    ]]
    pcall(function()
        script.Parent.Visible = not workspace.Values.Playing.Value
        --[[
        Using not in this situation is a better method, meaning it'll be the opposite of the actual value.
        So if it was true, it'd set the visibility to false here.
        ]]
    end)
end
0
More lines = more data, trust me, I've worked with 20,000 lines, it sucks. TheLuminent 970 — 7mo
0
In my opinion, this is the most optimal approach: https://pastebin.com/raw/31LQZz8Q Ziffixture 6785 — 7mo
0
The amount of lines doesn't affect anything in this context. Ziffixture 6785 — 7mo
0
Our programs are functionally equivalent, with the exception of mine using more efficient standards. Ziffixture 6785 — 7mo
0
I figured out the problem, I was supposed to use a local script in the GUI, But thanks for making the code significantly shorter, Ill accept your answer anyway ConceptBasics 2 — 7mo
Ad

Answer this question