Is this an ok script for health regen?? How can I make it more efficient I fear it may cause alot of lag since every player has one of these scripts in there character and max server size is 50
while true do
wait()
if script.Parent.Size.X.Scale <= 1 then
wait(0.095)
script.Parent.Size = script.Parent.Size + UDim2.new(0.001,0,0,0)
end
end
for any kind of math, just do +=, -=, /=, *= etc or whatever you need to, its faster to write and a lot easier to read. (I’m not sure on this but it might also be faster to run?)
Why didn’t you set the Y size, and I’m confused on. Why aren’t you just using an integer? Something like this:
local Health, MaxHealth = 10000, 10000 --// Adjustable health values
while task.wait(0.095) do
if Health < MaxHealth then
Health += 1
script.Parent.Size = Udim2.new(Health/MaxHealth, 0, 1, 0)
end
end
Also, this should go into the scripting support category.
Use a signal instead, like Humanoid.HealthChanged and connect that to changing the sizes. No need to check so many times per second if the value is unchanged.
-- assuming is in startercharacterscripts
local humanoid = script.Parent:WaitForChild('Humanoid')
humanoid.HealthChanged:Connect(function(health)
if script.Parent.Size.X.Scale <= 1 then
script.Parent.Size = script.Parent.Size + UDim2.new(0.001,0,0,0)
end
end)
You’ll prob wanna change 0.001 to Health/MaxHealh and don’t add it to the original size.