The HealthChanged Event doesn't fire until the Player's health is 0. Any issues with my script? It's a script inside the StarterCharacter. The Character is not nil, the Humanoid is not nil, and the PlayerFrame is not nil. I've debugged it once and it has worked one time. Does not work in Local, does not work in a regular Server.

local TweenService = require(game.ServerScriptService.Modules.TweenService)

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local lastHealth = humanoid.Health
local frame = character.Head:WaitForChild("PlayerFrame")

humanoid.HealthChanged:Connect(function(health)
	print("Test: "..health)
	local percent = health / humanoid.MaxHealth
	frame.Frame.HealthFrame.Health.Size = UDim2.new(percent, 0, 1, 0)
	
	local lostHealth = Instance.new("Frame")
	lostHealth.BorderSizePixel = 0
	lostHealth.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
	lostHealth.Size = UDim2.new((lastHealth - health)/100, 0, 1, 0)
	lostHealth.Position = UDim2.new(percent, 0, 0, 0)
	lostHealth.Parent = frame.Frame.HealthFrame
	
	local goal = {Size = UDim2.new(0, 0, 1, 0)}
	local properties = {Time = 0.5, Dir = Enum.EasingDirection.Out, Style = Enum.EasingStyle.Quad, Delay = 0.2}
	
	TweenService.tween(lostHealth, goal, properties)
	
	lastHealth = health
	
	game.Debris:AddItem(lostHealth, properties.Time)
end)

3 comments

0

Are you changing the humanoid's health on the client or server?

0

Server, but I think I just read something where it needs to be on the client, so I'll try that and then fire a RemoteEvent back to the server.

0

Yep that was the issue.