I’m so confused how such a simple bug is holding me back…
When the player resets it drains the frame, and when player spawns back then it doesn’t register no matter what
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local ts = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(.6)
char:WaitForChild("Humanoid").Changed:Connect(function()
print("changed to: "..char:WaitForChild("Humanoid").Health)
local tween = ts:Create(script.Parent, tweenInfo, {Size = UDim2.new(char:WaitForChild("Humanoid").Health / 100,0, 1,0)}):Play()
end)
You set tween to be nothing since :Play() doesn’t return anything
.Changed looks for anything change, use HealthChanged instead
No reason to do :WaitForHumanoid three times.
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local ts = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(.6)
local Humanoid = char:WaitForChild("Humanoid") :: Humanoid
Humanoid.HealthChanged:Connect(function(newHealth:number)
print("changed to: "..newHealth)
ts:Create(script.Parent, tweenInfo, {Size = UDim2.fromScale(newHealth / 100,1)}):Play()
end)ype or paste code here
The player gets a new humanoid when they respawn which makes the old humanoid connection obsolete. So you need to create a new connection to the new humanoid when the player respawns