Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I can't get Raycast to not harm a teammate?

Asked by 9 years ago

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)

2 answers

Log in to vote
1
Answered by 9 years ago

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.

Ad
Log in to vote
0
Answered by 9 years ago
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.

0
As I said, it is not a player. The problem is that it isn't reading the BrickColor Value. CoyoteChamp23 25 — 9y
0
you dont add Value at the end of TeamColor thegamingpro566 0 — 9y

Answer this question