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

How to change a player team by touching a brick?

I used that script on a brick but it didn't work:

script.Parent.Touched:connect(function(hit) Local player = hit.Parent.Name game.Players.player.Team = LabLabLab --Lol

1 comment

0

script.Parent.Touched:connect(function(hit) game.Players:GetPlayerFromCharacter(hit.Parent).Team = LabLabLab end)

1 answer

✓ Accepted answer

"connect" is deprecated, player.Team requires an object, and game.Players.Player would be an object when the variable player is simply a string

(saw a comment after posting, edited to use more reliable method)

script.Parent.Touched:Connect(function(hit)
	local user = game.Players:GetPlayerFromCharacter(hit.Parent)
	user.Team = game:GetService('Teams'):FindFirstChild('Team1')
end)

2 comments

0

Using FindFirstChild o find a player is unreliable, as anything with the same name as the player could go in Players

0

@incapaz you're right (though anything other than a player being in players would be stupid) it's better to use getplayerfromcharacter

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