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

How would I change this to make the Humanoid lose a random amount of health?

Asked by 5 years ago

Hi, at the moment this script will work but when my character touches the brick it sometimes loses health or gains health. I have tried making the numbers both negative but that just errors. So, I would appreciate it if anyone could help me with this?

script.Parent.Touched: connect(function(hit)
    local humanoid = hit.Parent:FindFirstChild("Humanoid")
    if humanoid ~= nil and humanoid.Health > 0 then
        local f = Instance.new("Fire", hit.Parent)
        f.Color = Color3.new(0, 85, 255)
        humanoid.Health = math.random(35, 100)

    end

end)

2 answers

Log in to vote
0
Answered by 5 years ago

You would have to subtract their health:

humanoid.Health = humanoid.Health - math.random(1, humanoid.Health)

Subtracting their health guarantees that they take damage.

0
This also never fails as the Health property keeps changing. DeceptiveCaster 3761 — 5y
0
Thank you very much I don't know why I didnt think of that! Cheesepotato999 8 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

Make the humanoid take damage

humanoid:TakeDamage(math.random(35,100))
0
^ No DeceptiveCaster 3761 — 5y
0
The health would then bug out and you would get an error. DeceptiveCaster 3761 — 5y
0
Well the health value would change, it's not always 100, it's an unknown number when you're scripting it(not playing), so you should throw in a variable mudathir2007 157 — 5y

Answer this question