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

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

Asked by 5 years ago
Edited 5 years ago

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

Log in to vote
0
Answered by 5 years ago

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
0
It’s best to format this as a debounce. if (hit.Parent:FindFirstChild("ForceField") then return end. Ziffixture 6913 — 5y
0
Thx, it worked! BrawlBattle 15 — 5y
0
:TakeDamage() on the humanoid also doesn’t do damage if a forcefield is used, but both ways can work. User#20279 0 — 5y
Ad

Answer this question