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

How can I make this script target Humanoids as well as players?

Asked by 7 years ago

I'm working an a game and I wanted for humanoids to fight enemies to make the game feel more lively. they do everything fine until they attack enemies that can only hurt specific teams. Thanks to this site I have been able to put them on teams but they still don't get hurt by the enemies. I have come to realize that the problem is not with the npcs, but with the enemies. I found that the script that the enemies had been using only targets players so the npcs didn't get hurt. How would I be able to make this script hurt humanoids and not just players?

script.Parent.Touched:connect(function(hit)

    local Player = game.Players:GetPlayerFromCharacter(hit.Parent)

    if Player and Player.TeamColor == BrickColor.new("Really red") then

        hit.Parent.Humanoid:TakeDamage(5)

    end

end)

1 answer

Log in to vote
0
Answered by 7 years ago

Instead of checking if the brick touching is part of player, check if it is a humanoid. Try something like this.

if part.Parent and part.Parent:FindFirstChild("Humanoid") then
    -- have the humanoid take damage
end
Ad

Answer this question