Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

If statement doesn't detect team color?

Asked by 9 years ago

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.

1 answer

Log in to vote
1
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
9 years ago

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)

0
I didn't know you needed to use BrickColor.new() when testing bools. Thanks! Octillerysnacker 115 — 9y
Ad

Answer this question