Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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

This discussion is preserved as it was. New answers, comments, and votes are closed.