Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Battery script not working?

So, this battery is supposed to represent health, but it re sizes for some reason. I don't know if I typed n the size wrong in the script, I don't know. Please look at these pictures to help answer this problem.

wait(.3)

Par=script.Parent.Parent.Parent.Parent.Parent
while true do
	wait()
	Heal=Par.Character.Humanoid
	wait()
	script.Parent.Parent.Health.Value=Heal.Health
	script.Parent.Parent.Total.Value=Heal.MaxHealth
	Min=150/Heal.MaxHealth
	script.Parent.Size=UDim2.new(0,Min*Heal.Health,1,0)	
	end

REALLY LOOK AT THESE PICTURES TO HELP ANSWER THE PROBLEM!

1 answer

✓ Accepted answer
local plr = game.Players.LocalPlayer
repeat wait() until plr.Character --Sometimes character isn't spawned by now
local hum = plr.Character.Humanoid
hum.HealthChanged:connect(function()
	script.Parent.Parent.Health.Value = hum.Health
	script.Parent.Parent.Total.Value = hum.MaxHealth
	script.Parent:TweenSize(UDim2.new(0, 150 * (hum.Health / hum.MaxHealth), 1, 0), "Out", "Sine", 0.2, true)
end)

You would have to put this in a local script so that when you do game.Players.LocalPlayerit finds your character. This would change the size whenever the health is changed as long as the health is less than max health (that is how HealthChanged event works). I added tween because I think it looks better, but if you remove the other stuff and change it back to .Size it would still work.

2 comments

0

Thanks :D

0

No problem!

This discussion is preserved as it was. New answers, comments, and votes are closed.