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

How to make a Zombie not Hurt you with a ForceField?

When my player has a ForceField, I'm still able to take damage from a zombie in my game. How can i add to this code so that the zombie cannot hurt me when my character has a ForceField?

Damage Script on the Left/Right "LowerArm"

function onTouched(hit)
    local human = hit.Parent:findFirstChild("Humanoid")
        if (human ~= nil) and (script.Parent.Parent.Humanoid.Health > 0) and (game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)) then
           human.Health = human.Health - 5
	end
end

script.Parent.Touched:connect(onTouched)

1 answer

✓ Accepted answer

Forcefields are stored in the player model, so you could add an if statement checking for that forcefield.

if hit.Parent:FindFirstChild("ForceField") == nil then
	human.Health = human.Health - 5
end

3 comments

0

It’s best to format this as a debounce. if (hit.Parent:FindFirstChild("ForceField") then return end.

0

Thx, it worked!

0

:TakeDamage() on the humanoid also doesn’t do damage if a forcefield is used, but both ways can work.

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