I’m trying to create a simple health bar updater, but here’s the catch. The GUI it’s located in does not reset upon spawn, which would make the typical health updating script work only one time. So I had to make some changes to create new events so that it will continue to function. For whatever reason, I can’t get it to work. It works for the first time, but after that it just does not work. I can’t figure out my logic…any help appreciated, thanks!
local plr = game.Players.LocalPlayer
local character = plr.Character or plr.CharacterAdded:Wait()
local function update_text(health)
script.Parent.TextLabel.Text = "Health [" .. math.floor(health+.5) .. "]"
script.Parent.Bar:TweenSize(UDim2.new(health/100,0,1,0),'Out','Quad',.01,true)
end
local function create_event(rig)
update_text(100)
rig:WaitForChild("Humanoid").HealthChanged:Connect(function(health)
update_text(health)
if health <= 0 then
print'awaiting test'
local test
repeat
wait()
test = ((plr.Character ~= rig) and plr.Character)
until test
create_event(test)
print'test made yay'
end
end)
end
create_event(character)