I made a unit shoot a ray but I want a way to make it not harm a team member or ally. I've tried
if part.Parent.TeamColor == Unit.TeamColor
and
if part.Parent.TeamColor.Value == Unit.TeamColor.Value
TeamColor is a BrickColor Value and I'm not sure what to do.
(in the hierarchy, this is correct)
COMMUNITY QUESTION
I can't get Raycast to not harm a teammate?
2 answers
FindPartOnRay() returns the Part it found, the Part's position, the surface normal at intersection (not needed much), and the Part's material.
So, you can do this
--// Pre-define raycast function to find a player
local HitPart = CastRay()
if HitPart then
local Player = game:GetService("Players"):GetPlayerFromCharacter(HitPart.Parent)
if Player then
if not(Player.TeamColor == Unit.TeamColor.Value) then
TakeDamage(Player)
end
end
end
If that doesn't work, try using the cmdbar in Studio to find and print TeamColor in the gun.
local function DamagePlayer(hitPlayerId, player, damage)
local hitPlayer = Players:GetPlayerByUserId(tonumber(hitPlayerId))
if (hitPlayer.TeamColor == player.TeamColor and Configurations.FriendlyFire.Value) or hitPlayer.TeamColor ~= player.TeamColor then
local humanoid = hitPlayer.Character:FindFirstChild('Humanoid')
if humanoid then
humanoid:TakeDamage(damage)
end
end
end
if the spawns are on workspace then do something like this
damage = 34
if hitPlayer.TeamColor == game.Workspace.Redspawn.BrickColor then
damage = 0
end
redspawn is the name of the team spawn you dont want to take damage
little something i did earlier use this to get to your problem. if this helps vote me up and if it doesnt comment.
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
As I said, it is not a player. The problem is that it isn't reading the BrickColor Value.
you dont add Value at the end of TeamColor