#HealthBar Like system not working
1 messages · Page 1 of 1 (latest)
`local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local frame = script.Parent
local healthBar = script.Parent.Health
healthBar.Size = UDim2.new(1, 0, 1, 0) -- Full size initially
local TweenService = game:GetService("TweenService")
local function updateHealthBar()
local healthPercent = script.Parent.Morale.Value / 100
local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
local goal = {Size = UDim2.new(healthPercent, 0, 1, 0)}
local tween = TweenService:Create(healthBar, tweenInfo, goal)
tween:Play()
end
humanoid.HealthChanged:Connect(updateHealthBar)
updateHealthBar() -- Initial update
`
Well it'll only update when the player's health has changed, because you didn't update that part
oh didnt quite catch that, thank you!
although when i replace it with
morale.Changed:Connect(updateHealthBar)
it doesnt really do anything still
** You are now Level 1! **
are you reducing morale in the right place? This looks like the value is placed in the GUI
yeah the value is in the GUI, is it not gonna work that way?
it should be on the player's character or the player itself so the server can change it. The server should make the value and manipulate it
the client can then grab its own morale and connect to changes
https://create.roblox.com/docs/reference/engine/classes/Humanoid#HealthChanged interesting.
in short, you don't have an quivalent of a "HealthChanged" event that you could compare to the "MoraleChanged" event that you appear to want. you pretty much have to make one for yourself.
healthchanged has the new value of health passed in, changed events don't have parameters, you have to read it again. bit weird but that's how the cookie crumbles 