So I'm making a game with classes, so I made a localscript with a few lines making BoolValues of each class. And that works because when I inspect player, there are all of the classes.
So I already made the script to give you the class items, and that works too.
The problem I have now Is trying to make a script that prevents you from re-clicking the Gui to change to that class if you're already that class.
Here's the script:
textButton = script.Parent spawns = {game.Workspace.SpawnLocation1 , game.Workspace.SpawnLocation2 , game.Workspace.SpawnLocation3 , game.Workspace.SpawnLocation4} player = script.Parent.Parent.Parent.Parent Trowel = game.ReplicatedStorage.ClassicTrowel:Clone() Builder = player:WaitForChild("Builder") textButton.MouseButton1Down:connect(function() if Builder.Value == false then Builder.Value = true script.Parent.Text = "5" wait(1) script.Parent.Text = "4" wait(1) script.Parent.Text = "3" wait(1) script.Parent.Text = "2" wait(1) script.Parent.Text = "1" wait(1) player.Character:MoveTo(spawns[math.random(1, #spawns)].Position) player.Character.Humanoid.MaxHealth = 200 player.Character.Humanoid.Health = 200 Trowel:Clone().Parent = player.Backpack Trowel:Clone().Parent = player.StarterGear script.Parent.Text = "Change to Builder" end end) else return end
I know there's an error, and it's been annoying me. It says:
'<eof>' expected near 'else'
I know that means that there should be whitespace where that is, but that completely erases the else part.
I have trouble with these conditional statements and where to place my 'ends'
Heres a small code that's fairly simple... I'm fairly good at this kind of coding due to I made a lot of Admin's and yea you kinda have to get good at If and else statements or the scripts breaks ;-;
data=false data2=true if data==true then print('data 1') elseif data2==true then print('data2') else print('hai') end
Your problem was that you ended your if statement, and then you ended your function, and then you put your else statement.
if's and elseif's/else's always share the same end.
This is what it's supposed to look like:
textButton.MouseButton1Down:connect(function() if Builder.Value == false then Builder.Value = true script.Parent.Text = "5" wait(1) script.Parent.Text = "4" wait(1) script.Parent.Text = "3" wait(1) script.Parent.Text = "2" wait(1) script.Parent.Text = "1" wait(1) player.Character:MoveTo(spawns[math.random(1, #spawns)].Position) player.Character.Humanoid.MaxHealth = 200 player.Character.Humanoid.Health = 200 Trowel:Clone().Parent = player.Backpack Trowel:Clone().Parent = player.StarterGear script.Parent.Text = "Change to Builder" else return end end)
Try to use proper indentation and syntax so that you don't encounter these errors as often. It makes it easier for you and others to read your code and find mistakes.