function onTouch(p) local h = p.Parent:FindFirstChild("Humanoid") if h then local ff = p.Parent:findFirstChild("ForceField") if h.Health == 100 and not ff then Instance.new("ForceField", h.Parent) script.Parent.TouchEnded:connect(function() if ff then Instance.new("ForceField", h.Parent):Destroy() end end) end end end script.Parent.Touched:connect(onTouch)
can someone please tell me why this isnt working
function onTouch(p) local h = p.Parent:FindFirstChild("Humanoid") if h then local ff = p.Parent:FindFirstChild("ForceField") if h.Health == 100 and not ff then local newff = Instance.new("ForceField", p.Parent) end end end function onTouchEnded(p) local h = p.Parent:FindFirstChild("Humanoid") if h then local ff = p.Parent:FindFirstChild("ForceField") if ff then ff:Destroy() end end end script.Parent.Touched:Connect(onTouch) script.Parent.TouchEnded:Connect(onTouchEnded)
The problem was that you destroyed a new ForceField, not the one that the player had. Also, look out for lowercase and uppercase characters, as some functions may not work if not written correctly.