my script is trying to make it to where every second, you lose 5 Health, but It just automatically kills you, the second you touch the part(this is a script within a part)
local HealthLoss = 5 script.Parent.Touched:connect(function(hit) if hit.Parent then local hum = hit.Parent:findFirstChild("Humanoid") if hum then droppedhealth = HealthLoss - HealthLoss hum.Health = droppedhealth end end end)
Any and all help is welcomed, maybe a reason on why this code persay was not working?
Let's break it down
The variable droppedhealth
is equal to HealthLoss
minus itself, which is 0, then you are setting the Humanoid
's health to droppedheatlh
, which is 0.
How to fix
You could get the Humanoid
's health, then subtract HealthLoss
local healthDrop = 5 part.Touched:connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then local hum = hit.Parent.Humanoid hum.Health = hum.Health - healthDrop end end)