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

How to make health value stay where it is with while loop?

Asked by 5 years ago
Edited 5 years ago

I'm trying to make a block damage on R. It continually puts the health back where it was, kinda like loopheal except it doesn't heal you. I don't want it to be like ff, where the damage is completely negated, so that if someone blocking with 30 hp takes 30 damage they die even if they're blocking. This is my attempt.

uis.InputBegan:connect(function(input)--Block
    if input.KeyCode == Enum.KeyCode.R then
        script.Parent.Parent.blocking.Value = true
        while script.Parent.Parent.blocking.Value == true do
        wait()
        hp = c.Humanoid.Health
        wait(0.1)
        c.Humanoid.Health  = hp 
        wait() 
        if blocking == false then return end
end
end 
end
end
end)
0
What's "hp" defined as? gmatchOnRoblox 103 — 5y
0
hp = Humanoid.Health. Basically I tried to make it say "Current Health = Current Health". Edbotikx 99 — 5y
0
im not sure whats what on the script, as the script is a bit messy, could you maybe explain it a bit more? cruizer_snowman 117 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

what you can do is at the beginning of the function before the while loop save a local variable which is the value of the players health like so:

uis.InputBegan:connect(function(input)--Block
if input.KeyCode == Enum.KeyCode.R then
        local hp = c.Humanoid.Health

then do your loop. You dont want to change the value in the while loop because it will continue to change and will not be the original value you intended. Hope this helps. Have a great day scripting!

Ad

Answer this question