Yeah, title doesn't make sense a bit. So basically, I'm trying to make soemthing that takes the LocalPlayer who touched the part, and then finds what team they are on and prints that they are on the right/wrong team. I have this so far:
1 | function touch(hit) |
2 | if hit.Parent:FindFirstChild( "Humanoid" ) ~ = nil and hit.Parent.TeamColor = = BrickColor.new( "Bright red" ) then |
3 | print ( "right team" ) |
4 | end |
5 | end |
6 | script.Parent.Touched:connect(touch) |
Sorry If I messed up, but any help will be good! Thanks!
Here is a tip that makes functions a lot less time consuming Instead of making
1 | function touch(hit) |
2 | end |
and having to connect the function at the end of the script,You can just do this
1 | Part.Touched:connect( function (hit) --Part being the part that you want to be touched. |
2 | end ) |
To answer your question, you can just use GetPlayerFromCharacter()
1 | Part.Touched:connect( function (hit) |
2 | local player = game.Players:GetPlayerFromCharacter(hit.Parent) |
3 | if hit.Parent:FindFirstChild( "Humanoid" ) ~ = nil and player.TeamColor = = BrickColor.new( "Bright red" ) then |
4 | print ( "Right Team" ) |
5 | else |
6 | print ( "Wrong Team" ) |
7 | end |
8 | end ) |
--EDIT: The text editor didn't seem to wont to cooperate with me :P