How do i fix my GetKilledGui

so im making Gui Named GetKilledGui, it basically When you Die it shows the players Health, Name And There Profile Picture but it Doesn’t Show The Players Health When you Die

This is The Script

local cam = game.Workspace.CurrentCamera
local KillText = script.Parent.KillText
local plr = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local ImageLabel = KillText.PlayerIcon
local Green = Color3.fromRGB(0, 255, 0)
local Red = Color3.fromRGB(255, 0, 4)

hum.Died:Connect(function()
	local mur = char.Humanoid:FindFirstChild("creator")
	local murChar = mur.Value.Character
	local murName = mur.Value.Name
	local murHealth = murChar:FindFirstChild("Humanoid").Health
	local murId = mur.Value.UserId
	if mur.Value then
		KillText.Visible = true
		cam.CameraSubject = murChar.Humanoid
		KillText.MuderName.Text = murName
		ImageLabel.Image = game.Players:GetUserThumbnailAsync(murId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
		
		if murHealth.Changed then
			local roundValue = (math.floor(murHealth))
			local maxH = murChar:FindFirstChild("Humanoid").MaxHealth
			KillText.MurderHP.Text = roundValue
			KillText.MurderHP.TextColor3 = Red:lerp(Green, roundValue / maxH)
		end
		
		wait(3)
		KillText.Visible = false
		cam.CameraSubject = hum
	end
end)

A couple problems here. Firstly you’re only setting the text conditionally if murHealth.Changed returns true/not nil, which it never will because this is not a valid member of Humanoid.Health (so it will return nil)

I think what you’re trying to do here is use Instance.Changed (which is an event) to live-update the UI to show the current health.

what you should be doing is set the value initially and update the health text every time the humanoid is changed, so something along the lines of:

local cam = game.Workspace.CurrentCamera
local KillText = script.Parent.KillText
local plr = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local ImageLabel = KillText.PlayerIcon
local Green = Color3.fromRGB(0, 255, 0)
local Red = Color3.fromRGB(255, 0, 4)

hum.Died:Connect(function()
	local mur = char.Humanoid:FindFirstChild("creator")
	local murChar = mur.Value.Character
	local murName = mur.Value.Name
	local murHealth = murChar:FindFirstChild("Humanoid").Health
	local murId = mur.Value.UserId
	if mur.Value then
		KillText.Visible = true
		cam.CameraSubject = murChar.Humanoid
		KillText.MuderName.Text = murName
		ImageLabel.Image = game.Players:GetUserThumbnailAsync(murId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
		
		local roundValue = (math.floor(murHealth))
		local maxH = murChar:FindFirstChild("Humanoid").MaxHealth
		KillText.MurderHP.Text = roundValue
		KillText.MurderHP.TextColor3 = Red:lerp(Green, roundValue / maxH)
		murChar.Humanoid.Changed:connect(function()
			KillText.MurderHP.Text = roundValue
			KillText.MurderHP.TextColor3 = Red:lerp(Green, roundValue / maxH)
		end)
		
		wait(3)
		KillText.Visible = false
		cam.CameraSubject = hum
	end
end)

is probably what you’re looking for.

1 Like

yeah thats what im looking for thanks for helping

1 Like
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")

local Camera = workspace.CurrentCamera
local Frame = script.Parent
local KillText = Frame:WaitForChild("KillText")
local KillIcon = KillText:WaitForChild("PlayerIcon")

local function OnHumanoidDied()
	local KillerTag = Humanoid:FindFirstChild("creator")
	if KillerTag then
		local KillerPlayer = KillerTag.Value
		if KillerPlayer then
			local KillerCharacter = KillerPlayer.Character
			local KillerHumanoid = KillerCharacter.Humanoid
			
			KillerHumanoid.HealthChanged:Connect(function(KillerHealth)
				KillText.MurderHP.Text = math.round(KillerHealth)
				KillText.MurderHP.TextColor3 = Color3.new(1, 0, 0):lerp(Color3.new(0, 1, 0), KillerHealth / KillerHumanoid.MaxHealth)
			end)
			
			Camera.CameraSubject = KillerHumanoid
			KillText.Visible = true
			KillText.MuderName.Text = KillerPlayer.Name
			KillText.MurderHP.Text = math.round(KillerHumanoid.Health)
			KillText.MurderHP.TextColor3 = Color3.new(1, 0, 0):lerp(Color3.new(0, 1, 0), KillerHumanoid.Health / KillerHumanoid.MaxHealth)

			local Succ, Res = pcall(function()
				return Players:GetUserThumbnailAsync(KillerPlayer.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
			end)
			if Succ then
				if Res then
					KillIcon.Image = Res
				end
			else
				warn(Res)
			end
			
			task.wait(3)
			KillText.Visible = false
			Camera.CameraSubject = Humanoid
		end
	end
end

Humanoid.Died:Connect(OnHumanoidDied)

There are a few issues with your script as well (albeit, slightly less).

1 Like

what did you change in the script?