Hi there! What is wrong with this simple script? Thanks in advance!
TeamColor = BrickColor.new("Bright blue") ---For this script to work, i need --the exact color of the team that may touch it only replace the stuff inside "" script.Parent.Touched:connect(function(hit) print(hit) if hit.Parent.TeamColor == BrickColor.new("Bright blue") then hit.Parent.Humanoid.Health = 0 else return end end)
The Character (the physical component of the Player) doesn't have a TeamColor property. It's just a Model.
In addition, you currently aren't doing a check to prevent errors involving the possible non-existence of hit.Parent
or of hit.Parent.Humanoid
.
We have to get the Player
object corresponding to the Character
and check its TeamColor.
script.Parent.Touched:connect( function(hit) if hit.Parent then -- Check to prevent errors local character = hit.Parent local player = game.Players:GetPlayerFromCharacter(character) if player and player.TeamColor == TeamColor then -- It actually is a Player (not some other object) -- and they are on the `TeamColor` colored team character.Humanoid.Health = 0 end end end )