Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

What's this team script problem?

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

1 comment

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).

1 answer

✓ Accepted answer

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!

This discussion is preserved as it was. New answers, comments, and votes are closed.