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

Why does this skip an entire block of code?

Asked by 10 years ago

I have two scripts that are supposed to work together to determine the frozen player. (They communicate by changing their names)

script 1:

_G.scriptperson2 = script.Parent.gamelogic

function display(text)
    local text2 = game.ServerStorage.text.Value
    text2 = text
    wait(3)
    text2 = ""
end
while true do


repeat wait() until _G.scriptperson.Name == "ready"

    repeat wait() until _G.Team2Player.Character.ingame.WalkSpeed == 0
        wait(3)
        if _G.scriptperson2.Name ~= "checkdone" then
        script.Name = "checkdone"
        _G.scriptperson2.Disabled = true
        for i,v in pairs(game.Players:GetChildren()) do
            if v.TeamColor == "Bright blue" then
                v.leaderstats.Wins.Value = v.leaderstats.Wins.Value + 1
            end
        end
        display("Red captain has been frozen! Blue team wins!")
        script.Name = "gamedone"
        wait(1)
        script.Name = "gamelogic2"
        _G.scriptperson2.Disabled = false
        elseif _G.scriptperson2.Name == "checkdone" then return end
end

script 2:

_G.scriptperson3 = script.Parent.gamelogic2
function display(text)
    local text2 = game.ServerStorage.text.Value
    text2 = text
    wait(3)
    text2 = ""
end

while true do
    repeat wait() until _G.scriptperson.Name == "ready"

        repeat wait() until _G.Team1Player.Character.ingame.WalkSpeed == 0
        if _G.scriptperson3.Name ~= "checkdone" then
        _G.scriptperson3.Disabled = true
        script.Name = "checkdone"
            for i,v in pairs(game.Players:GetChildren()) do
            if v.TeamColor == "Bright red" then
                v.leaderstats.Wins.Value = v.leaderstats.Wins.Value + 1
            end
            end
        display("Blue captain has been frozen! Red team wins!")
        script.Name = "gamedone"
        wait(1)
        script.Name = "gamelogic"
        _G.scriptperson3.Disabled = false
        elseif _G.scriptperson3.Name == "checkdone" then return end
end

For the most part, they work perfectly, the check for the names of the other scripts and change their own names accordingly, but one thing is wrong! It skips the entire block of each code that goes:

    for i,v in pairs(game.Players:GetChildren()) do
            if v.TeamColor == "Bright red" then
                v.leaderstats.Wins.Value = v.leaderstats.Wins.Value + 1
            end
            end
        display("Blue captain has been frozen! Red team wins!")

Why does it do this? Neither of the scripts break. They keep looping the way they are supposed to, it just skips the block above in each of them.

0
Does" v.TeamColor" need to be checked against a color3 value or a brick color value? GoldenPhysics 474 — 10y
0
I think it's a brick color. froggodude 15 — 10y
0
Maybe 'TeamColor.name == "Bright red"' GoldenPhysics 474 — 10y
0
Golden was right about it needing to be a BrickColor value. Change it to v.TeamColor = BrickColor.new("Bright red") Aethex 256 — 10y
0
Ok thanks guys! froggodude 15 — 10y

1 answer

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

The expression

playerInstance.TeamColor == "Bright red"

will always be false. This is because TeamColor is a BrickColor value, and "Bright red" is a string.

a == b is always false when a and b are different types. In this case, a is a BrickColor and b is a string, so we know without having to actually check that playerInstance.TeamColor == "Bright red" is false.

This section in the BrickColor article tells us that we can compare BrickColor values using equals, or their names (which are strings).

We can change this to one of the following (or one of several others):

playerInstance.TeamColor == BrickColor.new("Bright red")
playerInstance.TeamColor.Name == "Bright red"
Ad

Answer this question