How can i make an object not kill the player if they have a forcefield

im creating boulders that kill you.
i made the script tell the part to change the players health to 0 when its touched. when i playtest my game the boulder killed me even though i had a forcefield. is there a way to fix this?

current script:
script.Parent.Touched:connect(function(hit)
if hit and hit.Parent and hit.Parent:FindFirstChild(“Humanoid”) then
hit.Parent.Humanoid.Health = 0
end
end)

i also tried doing this:
script.Parent.Touched:connect(function(hit)
if hit and hit.Parent and hit.Parent:FindFirstChild(“Humanoid”) and not hit.Parent:FindFirstChild(“ForceField”) then
hit.Parent.Humanoid.Health = 0
end
end)

1 Like

In order to account for forcefields, you should use the Humanoid:TakeDamage() method instead of directly modifying the health property.

2 Likes

A post was merged into an existing topic: Feedback - Bypassing the 30 Character Limit