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

Getting teamcolor from player, for base flag?

I've been scripting for a bit so my brain doesn't really understand the words anymore, if you know the feeling.

local Flag = script.Parent.Parent.Flag

enabled = true

function onClick(Character)
	local Player = game.Players:GetPlayerFromCharacter(Character)

	script.Parent.TeamColor.Value = Player.TeamColor




end
script.Parent.ClickDetector.MouseClick:connect(onClick)

Returns a "attempt to index local Player (a nil value)"

I'm pre-occupied so, even while looking at other base scripts from FM, I can't physically read them to tell what's wrong right now. Thanks in advanced.

1 answer

✓ Accepted answer

Your problem is that the MouseClick function returns the Player who clicked not the Character who clicked. This makes it so that on line 8 you are searching for the player with the player rather than the player's character.

local flag = script.Parent.Parent.Flag
local enabled = true

script.Parent.ClickDetector.MouseClick:connect(function(player)
	script.Parent.TeamColor.Value = player.TeamColor
end)

9 comments

0

...Oh. My bad. I thought it returned the character. Thanks.

0

No problem :)

0

I've got one more question. Is this supposed to work? I don't think it's the proper way to compare colors. if script.Parent.TeamColor.Value == "Bright Red" then

0

If you are using a BrickColor3 value, then it should look like this: if script.Parent.TeamColor.Value == BrickColor3.new("Bright Red") then. If it is a string value, the way you have it is fine.

0

I'm using a BrickColor value, not a brickcolor3 value

0

That's what I meant

0

Doesn't seem to be working?

0

I fixed it. You were a tiny bit off - BrickColor.new("Bright red"), is correct, the 3 was unneeded, but I instantly realized that - we both forgot , "red" shouldn't be capitalized

0

Whoops yeah I just copy and pasted yours haha!

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