The script is supposed to make the player's team change when the value called "mech" changes. Unfortunately, the player is staying neutral, and is spawning at default spawn! Why is that happening? here is the script
while true do wait(0.1) if script.Parent.Parent.MechValue.Value == 1 then script.Parent.Parent.Parent.Parent.Neutral = false script.Parent.Parent.Parent.Parent.TeamColor = BrickColor.new("Institutional white") print("Picked white") elseif script.Parent.Parent.MechValue.Value == 2 then script.Parent.Parent.Parent.Parent.Neutral = false script.Parent.Parent.Parent.Parent.TeamColor = BrickColor.new("Medium stone gray") print("Picked gray") elseif script.Parent.Parent.MechValue.Value == 3 then script.Parent.Parent.Parent.Parent.Neutral = false script.Parent.Parent.Parent.Parent.TeamColor = BrickColor.new("Really black") print("Picked black") end end
Please help!!! Thank you!!! OUTPUT:Players.Player.PlayerGui.ScreenGui.TextButton.Script:17: 'end' expected (to close 'while' at line 1) near '<eof>'
[EDIT: Fixed if error]
First, let's clean up your code with a little tabbing.
Next, use elseifs instead of multiple if statements.
Lastly, players have a Neutral value that defaults to True
, so you must set it to False
to allow players to change teams.
Code that reflects changes:
while true do wait(0.1) if script.Parent.Parent.MechValue.Value == 1 then script.Parent.Parent.Parent.Parent.Neutral = false script.Parent.Parent.Parent.Parent.TeamColor = BrickColor.new("Institutional white") print("Picked white") elseif script.Parent.Parent.MechValue.Value == 2 then script.Parent.Parent.Parent.Parent.Neutral = false script.Parent.Parent.Parent.Parent.TeamColor = BrickColor.new("Medium stone gray") print("Picked gray") elseif script.Parent.Parent.MechValue.Value == 3 then script.Parent.Parent.Parent.Parent.Neutral = false script.Parent.Parent.Parent.Parent.TeamColor = BrickColor.new("Really black") print("Picked black") end end
Also, next time, if this is all the code in the script, I suggest using game.Players.LocalPlayer within a LocalScript instead to reduce the amount of parent
s.