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.
01 | local player = game.Players.LocalPlayer |
02 | game.Workspace.Intermission.Changed:connect( function () |
03 | if game.Workspace.Intermission.Value = = true then |
04 | script.Parent.Parent.Visible = true |
05 | game.Workspace.Inttime.Changed:connect( function () |
06 | local Inttime = workspace.Inttime.Value |
07 | script.Parent.Plrname.Text = player.Name |
08 | script.Parent.Inttime.Text = (Inttime.. " Until Round" ) |
09 | script.Parent.BackgroundColor = player.TeamColor |
10 | else |
11 | script.Parent.BackgroundColor = BrickColor.White() |
12 | end |
13 | end ) |
14 | 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:
01 | local player = game.Players.LocalPlayer |
02 | game.Workspace.Intermission.Changed:connect( function () |
03 | if game.Workspace.Intermission.Value = = true then |
04 | script.Parent.Parent.Visible = true |
05 | game.Workspace.Inttime.Changed:connect( function () |
06 | local Inttime = workspace.Inttime.Value |
07 | script.Parent.Plrname.Text = player.Name |
08 | script.Parent.Inttime.Text = (Inttime.. " Until Round" ) |
09 | script.Parent.BackgroundColor = player.TeamColor |
10 | end ) |
11 | else |
12 | script.Parent.BackgroundColor = BrickColor.White() |
13 | end |
14 | 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.
01 | local player = game.Players.LocalPlayer |
02 | game.Workspace.Intermission.Changed:connect( function () --FUNCTION 1 | This is ok! |
03 | if game.Workspace.Intermission.Value = = true then -- If statement |
04 | script.Parent.Parent.Visible = true |
05 | game.Workspace.Inttime.Changed:connect( function () -- FUNCTION 2 | ERROR you did not close the if statement, this will not work!!! |
06 | local Inttime = workspace.Inttime.Value |
07 | script.Parent.Plrname.Text = player.Name |
08 | script.Parent.Inttime.Text = (Inttime.. " Until Round" ) |
09 | script.Parent.BackgroundColor = player.TeamColor |
10 | else --This cannot be in another function |
11 | script.Parent.BackgroundColor = BrickColor.White() |
12 | end |
13 | end ) |
14 | 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:
01 | local player = game.Players.LocalPlayer |
02 | game.Workspace.Intermission.Changed:connect( function () |
03 | if game.Workspace.Intermission.Value = = true then |
04 | script.Parent.Parent.Visible = true |
05 | game.Workspace.Inttime.Changed:connect( function () |
06 | local Inttime = workspace.Inttime.Value |
07 | script.Parent.Plrname.Text = player.Name |
08 | script.Parent.Inttime.Text = (Inttime.. " Until Round" ) |
09 | script.Parent.BackgroundColor = player.TeamColor |
10 | end ) |
11 | else |
12 | script.Parent.BackgroundColor = BrickColor.White() |
13 | end |
14 | end ) |