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

if statement not working properly?

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!

1 comment

0

Appropriately, it's "elseif".

1 answer

✓ Accepted answer

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

5 comments

0

More lines = more data, trust me, I've worked with 20,000 lines, it sucks.

0

In my opinion, this is the most optimal approach: https://pastebin.com/raw/31LQZz8Q

0

The amount of lines doesn't affect anything in this context.

0

Our programs are functionally equivalent, with the exception of mine using more efficient standards.

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

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