In my game there are 3 teams: Blue, Red, and Spectators (white). So my script deals with what happens when a player says they are playing:
--VARS local playing = false local button = script.Parent --COLOR FUNCTIONS function green() --Turns button green and changes text button.BackgroundColor3 = Color3.new(0,255,0) button.Text = "Playing? Yes" script.Parent.Parent.playBool.Value = true --Changes a var used for another script end function red()--Same thing but turns button red button.BackgroundColor3 = Color3.new(255,0,0) button.Text = "Playing? No" script.Parent.Parent.playBool.Value = false--Same thing end --MAIN SCRIPT FUCTION button.MouseButton1Down:connect(function () playing = not playing --Switches playing mode if playing and game.Players.LocalPlayer.TeamColor ~= "White" then --If they are playing and are not on Spectators (Team White) add them to playing roster workspace.ReadyChecker.PeoplePlaying.Value = workspace.ReadyChecker.PeoplePlaying.Value + 1 green() elseif playing and game.Players.LocalPlayer.TeamColor == "White" then--If they are playing and are on Spectators, chew them out for not being on a team button.Text = "You must choose a team!" wait(2) button.Text = "Playing? No" else --If it's none of the above set them to spectators. workspace.ReadyChecker.PeoplePlaying.Value = workspace.ReadyChecker.PeoplePlaying.Value - 1 red() game.Players.LocalPlayer.TeamColor = BrickColor.new("White") game.Players.LocalPlayer.Character.Humanoid.Health = 0 end end)
The problem I'm having has to do with Spectators saying they are playing. This happens at line 21 where the player is told they must choose a team if game.Players.LocalPlayer.TeamColor == "White"
. For some reason the if
statement doesn't check if the LocalPlayer
is on the White team and kills the player instead to put them on the team they are already on. So what is the problem and how can it be fixed?
NOTE: This is in a local script.
Just like line 28, you need to use BrickColor.new! Here's your fixed code:
--VARS local playing = false local button = script.Parent --COLOR FUNCTIONS function green() --Turns button green and changes text button.BackgroundColor3 = Color3.new(0,255,0) button.Text = "Playing? Yes" script.Parent.Parent.playBool.Value = true --Changes a var used for another script end function red()--Same thing but turns button red button.BackgroundColor3 = Color3.new(255,0,0) button.Text = "Playing? No" script.Parent.Parent.playBool.Value = false--Same thing end --MAIN SCRIPT FUCTION button.MouseButton1Down:connect(function () playing = not playing --Switches playing mode if playing and game.Players.LocalPlayer.TeamColor ~= BrickColor.new("White") then --If they are playing and are not on Spectators (Team White) add them to playing roster workspace.ReadyChecker.PeoplePlaying.Value = workspace.ReadyChecker.PeoplePlaying.Value + 1 green() elseif playing and game.Players.LocalPlayer.TeamColor == BrickColor.new("White") then--If they are playing and are on Spectators, chew them out for not being on a team button.Text = "You must choose a team!" wait(2) button.Text = "Playing? No" else --If it's none of the above set them to spectators. workspace.ReadyChecker.PeoplePlaying.Value = workspace.ReadyChecker.PeoplePlaying.Value - 1 red() game.Players.LocalPlayer.TeamColor = BrickColor.new("White") game.Players.LocalPlayer.Character.Humanoid.Health = 0 end end)