local part = script.Parent local team = game.Teams["Team"] part.Touched:Connect(function(plr) plr.Team = team end)
5: Team is not a valid member of Part
How do i do that?
Thanks for helping me if you do!
Hit
is the part that hit the touch part.
The thing hitting the part may or may not be part of a character.
You can check if the part touching the touch part is a player by using Players:GetPlayerFromCharacter(hit.Parent)
the code below checks if the thing touching the part is a player, if it is not, then exit out of the function:
local Players = game:GetService("Players") local part = script.Parent local team = game.Teams["Team"] --"Team" is your team name part.Touched:Connect(function(hit) local player = Players:GetPlayerFromCharacter(hit.Parent) if not player then return end player.Team = team end)
Touched fires with the Part it touched, not the Player so we have to get the Player from the Character. The
local Players = game:GetService("Players") local Part = script.Parent local Team = game.Teams["Team"] Part.Touched:Connect(function(TouchedPart) local Player = Players:GetPlayerFromCharacter(TouchedPart.Parent) if Player then Player.Team = Team end end)
local part = script.Parent local team = game.Teams["Team"] part.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("HumanoidRootPart") then local player = game.Players:GetPlayerFromCharacter(hit.Parent) player.Team = team end end)