Problem: i have this code to update a gui baste on game values, and when i added the second changed function, the else was underlined in red indicating an error, and i was hoping someone could help me out :D THANKS.
local player = game.Players.LocalPlayer game.Workspace.Intermission.Changed:connect(function() if game.Workspace.Intermission.Value == true then script.Parent.Parent.Visible = true game.Workspace.Inttime.Changed:connect(function() local Inttime = workspace.Inttime.Value script.Parent.Plrname.Text = player.Name script.Parent.Inttime.Text = (Inttime.. " Until Round") script.Parent.BackgroundColor = player.TeamColor else script.Parent.BackgroundColor = BrickColor.White() end end) end)
You just used it in the wrong place in your code. You need to continue an "else" statement off of an existing "if" statement, in the same block of code.
(Also, you should try to use indentations, it helps keep your code cleaner, and makes it way easier for us to help you debug it)
So try this:
local player = game.Players.LocalPlayer game.Workspace.Intermission.Changed:connect(function() if game.Workspace.Intermission.Value == true then script.Parent.Parent.Visible = true game.Workspace.Inttime.Changed:connect(function() local Inttime = workspace.Inttime.Value script.Parent.Plrname.Text = player.Name script.Parent.Inttime.Text = (Inttime.. " Until Round") script.Parent.BackgroundColor = player.TeamColor end) else script.Parent.BackgroundColor = BrickColor.White() end end)
Anyways, it should work now. If you have any further questions/problems please leave a comment below. Hope I helped :P
You are calling a totally new function before ending the other function. You need to move the else out of the other function or figure out how to avoid having the else in another function.
local player = game.Players.LocalPlayer game.Workspace.Intermission.Changed:connect(function() --FUNCTION 1 | This is ok! if game.Workspace.Intermission.Value == true then -- If statement script.Parent.Parent.Visible = true game.Workspace.Inttime.Changed:connect(function() -- FUNCTION 2 | ERROR you did not close the if statement, this will not work!!! local Inttime = workspace.Inttime.Value script.Parent.Plrname.Text = player.Name script.Parent.Inttime.Text = (Inttime.. " Until Round") script.Parent.BackgroundColor = player.TeamColor else --This cannot be in another function script.Parent.BackgroundColor = BrickColor.White() end end) end)
Please put some spacing in your script above so that if you need help figuring how to get the if statement in one function or accomplish this script with a different method, I can help. I hope this helps you see your issue. Let me know if this is wrong!
It looks like it underlined else because it was expecting an end for the function before the else. Try this:
local player = game.Players.LocalPlayer game.Workspace.Intermission.Changed:connect(function() if game.Workspace.Intermission.Value == true then script.Parent.Parent.Visible = true game.Workspace.Inttime.Changed:connect(function() local Inttime = workspace.Inttime.Value script.Parent.Plrname.Text = player.Name script.Parent.Inttime.Text = (Inttime.. " Until Round") script.Parent.BackgroundColor = player.TeamColor end) else script.Parent.BackgroundColor = BrickColor.White() end end)