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

Getting teamcolor from player, for base flag?

Asked by 9 years ago

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

Log in to vote
2
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
9 years ago

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)
0
...Oh. My bad. I thought it returned the character. Thanks. Maxwell_Edison 105 — 9y
0
No problem :) BlackJPI 2658 — 9y
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 Maxwell_Edison 105 — 9y
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. BlackJPI 2658 — 9y
View all comments (5 more)
0
I'm using a BrickColor value, not a brickcolor3 value Maxwell_Edison 105 — 9y
0
That's what I meant BlackJPI 2658 — 9y
0
Doesn't seem to be working? Maxwell_Edison 105 — 9y
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 Maxwell_Edison 105 — 9y
0
Whoops yeah I just copy and pasted yours haha! BlackJPI 2658 — 9y
Ad

Answer this question