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

What's this team script problem?

Asked by 10 years ago

I'm trying to make a local script detect what the teams are, the colors of the teams "NATO" Bright blue and "OPFOR" Bright red. So what's the problem with this?

if script.Parent.Parent.Team=="NATO" then
    script.Parent.Scripts.PlayerRig.Disabled=true
    script.Parent.Scripts.PlayerRig2.Disabled=false
    wait(0)
    script.Parent.Scripts.Animate.Disabled=false
    script.Parent.Scripts.HatAnimationSoundRemover=false
elseif script.Parent.Parent.Team=="OPFOR" then
    script.Parent.Scripts.PlayerRig.Disabled=false
    script.Parent.Scripts.PlayerRig2.Disabled=true
    wait(0)
    script.Parent.Scripts.Animate.Disabled=false
    script.Parent.Scripts.HatAnimationSoundRemover=false
end
0
What kind of object is script.Parent.Parent.Team? I assume it's a property, but no such property exists. If you're trying to access player.TeamColor, you'll get a BrickColor-value, not a string (team-name). Ravenshield 180 — 10y

1 answer

Log in to vote
1
Answered by 10 years ago

Assuming you're actually attempting to use player.TeamColor, not player.Team, you can do it like this:

local teams = { 
        ["NATO"] = BrickColor.new("Bright blue"); -- Optionally BrickColor.Blue()
        ["OPFOR"] = BrickColor.new("Bright red"); -- BrickColor.Red() returns Really red.
}

if script.Parent.Parent.TeamColor == teams["NATO"] then 
    script.Parent.Scripts.PlayerRig.Disabled = true
    script.Parent.Scripts.PlayerRig2.Disabled = false
elseif script.Parent.Parent.TeamColor == teams["OPFOR"] then
    script.Parent.Scripts.PlayerRig.Disabled = false
    script.Parent.Scripts.PlayerRig2.Disabled = true
end
-- Moved these two lines down here, as they both happen in both incidents. However, if you have several teams and you only want this applied to these two teams, you'll have to move it back.
script.Parent.Scripts.Animate.Disabled = false
script.Parent.Scripts.HatAnimationSoundRemover = false

If script.Parent.Parent is the Player, and this is a LocalScript, I advise you to assign a variable to game.Players.LocalPlayer, rather than jumping through the hierarchy all the time!

Ad

Answer this question