Recently with my game I’ve been trying to implement a special health pickup that when touched will heal you all the way, but will also increase your health to 250 for a short amount of time, then over the course of a few seconds the HP will dwindle back down to 100. More or less an Overheal mechanic, Think Medic from TF2. Unfortunately with how Roblox is (at least in my experience) The normal MaxHP is 100 and the regular health wont go above that, so I tried to get around this in this script by modifying a health pick up I already had.
I’ve had a couple issues come out of this:
-
If damage is taken after the item is picked up then the MaxHP stays at 250 and wont go back down to 100. I’ve tried putting a line in the script that if the players HP is <= 100 then the MaxHP would go back to 100 but that didn’t work. If the item is picked up again the MaxHP will hit 400 and so on.
-
The HP won’t “De-Generate” I’ve been trying to write the script to at the very least get the HP and MaxHP to go down naturally over time in increments of 10 every second, but its not working. (In the script below I’m aware this likely isn’t the proper formula/code for the math but I just want to see if something happens)
These 2 are the biggest reasons for this post.
I’ve tried looking across the devforum and YouTube, but I can’t find anything. The only things I keep finding are “OverHead UI” and nothing about “OverHeal”. The only thing close is a separate armor pick up that goes over the HP (which is something I want to add later on after the HP pickups are finished and fixed)
The script I’m using is a recycled script from another HP pickup I have
--local stuff
local Item = script.Parent
local cross = script.Parent.Cross
debounce = true
local healAmount = 150
local megaheal = 100
local player = game.Players.LocalPlayer
--Item will disappear and reappear in a few seconds
Item.Touched:Connect (function(hit)
local humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")
if humanoid and debounce == true then
debounce = false
Item.Transparency = 1
cross.Transparency = 1
Item.CanCollide = false
local smallHeal = humanoid.Health
local smallHealth = smallHeal + megaheal
local health = humanoid.MaxHealth
local newHealth = health + healAmount
humanoid.MaxHealth = newHealth
humanoid.Health = smallHealth
-- If the max health is higher than 100 it needs to go back to 100 slowly--
if humanoid.MaxHealth == 250 then
local degenRate = 10 -- Rate Overheal goes down --
local degenStep = 1 -- Wait time in every -10 --
if humanoid.MaxHealth == 250 then
local degenTime = wait(degenStep)
local dh = degenTime*degenRate-humanoid.MaxHealth
humanoid.Health = math.min(humanoid.Health - dh, humanoid.MaxHealth)
end
if humanoid.Health <= 100 then
humanoid.MaxHealth = 100
end
end
wait(5)
Item.Transparency = 0.95
cross.Transparency = 0
debounce = true
end
end)