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!
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)
Fixed it, I was trying to write it as quick as possible to post it before you or anyone else :P
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)
This discussion is preserved as it was. New answers, comments, and votes are closed.
6 comments
Hit is a part, not a player. If you want to get a player from a part, then get the part's parent and use Player:GetPlayerFromCharacter() in order to get the player from the character. You also have to check if you get a player from the part's parent or not.
i think you identified "plr" as the part, thats why it searches "team" in the part and not the player..
how?
i can't do it myself, i don't understand what you are saying
nvm i figured out
rip. i just replied with an answer. hopefully that helps clear things up