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

What is wrong with this team changing script?

The script is supposed to change a player's team on touched. When a player touches it, however, I get the error "TeamColor is not a valid member of Model"

function onTouch(part)
	if part.Parent:FindFirstChild("Humanoid") then
		part.Parent.TeamColor = BrickColor.new("Bright red")
	end
end

script.Parent.Touched:connect(onTouch)

Any help?

1 answer

✓ Accepted answer

TeamColor only works on players. You're trying to use it on a character.

To get the player from the character you can use the GetPlayerFromCharacter(CharacterHere) function from the Players tab. Our character is the part's parent. So this is simple. We do the following,

function onTouch(part)
    if part.Parent:FindFirstChild("Humanoid") then
	local player = game.Players:GetPlayerFromCharacter(part.Parent)--get player
        player.TeamColor = BrickColor.new("Bright red")--use player
    end
end

script.Parent.Touched:connect(onTouch)

That should work.

Good Luck!

2 comments

0

Aha, thanks! Didn't know this!

0

You're welcome!

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