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

How to change a player team by touching a brick?

Asked by 5 years ago

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

0
script.Parent.Touched:connect(function(hit) game.Players:GetPlayerFromCharacter(hit.Parent).Team = LabLabLab end) LostPast 253 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

"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)
0
Using FindFirstChild o find a player is unreliable, as anything with the same name as the player could go in Players User#19524 175 — 5y
0
@incapaz you're right (though anything other than a player being in players would be stupid) it's better to use getplayerfromcharacter vanilla_wizard 336 — 5y
Ad

Answer this question