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

My anti team kill script is having problems with fulfilling the command :/ help?

Asked by 7 years ago
function HIT_HANDLE(hit, dmg, tags)
    if hit.Parent:FindFirstChild("Humanoid") then
        hit.Parent.Humanoid:TakeDamage(75)
        PlaySound("Hit")
        PlaySound("Dead")
    end
end

So basically this is the original part of the script where if the tool (the throwing knife is the tool) hits a player, it deals 75 damage, what I have been trying to do is set up the script so that if the player the throwing knife hits is a teammate, it wont do damage, and only would if it wasn't a teammate, this was my best attempt at it and still was having troubles... :/ :

function HIT_HANDLE(hit, dmg, tags)
    if hit.Parent:FindFirstChild("Humanoid") then
        if hit.Parent.TeamColor ~= Player.TeamColor then
            hit.Parent.Humanoid:TakeDamage(75)
             PlaySound("Hit")
        end
    end
end

Thanks in advance to anyone who helps me figure this out!

1
Characters do not have a TeamColor. View the output. cabbler 1942 — 7y

1 answer

Log in to vote
0
Answered by
FiredDusk 1466 Moderation Voter
7 years ago

Like cabbler said, you can't change the Player's TeamColor by just getting the Character. So then we use this function called ":GetPlayerFromCharacter()".

function HIT_HANDLE(hit, dmg, tags)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- hit.Parent is the character but we use his function to get the player's character.
    if hit.Parent:FindFirstChild("Humanoid") and player then -- we will just check if it is a player too.
        if player.TeamColor ~= Player.TeamColor then --Not sure what the "Player" is, I left that how it is.
            hit.Parent.Humanoid:TakeDamage(75)
             PlaySound("Hit")
        end
    end
end
Ad

Answer this question