On Death Gui not detecting character?

For some reason, I can’t seem to detect a player using a LOCAL script in StarterPlayerScripts, however, it does detect the player adding to the game but when it trys to find the player, it doesn’t work?
image

Here’s the code:

local player = game.Players.LocalPlayer
local playergui = player:WaitForChild("PlayerGui")
local char = player.Character

player.CharacterAdded:Connect(function()
	print("Player Character has been loaded!")
end)


while wait(1) do
	if char then --not detecting if the character has been found?
		if char.Humanoid.Died then
			playergui.ToolsGui.Enabled = true --I have tried :WaitForChild and :FindFirstChild, but I just tried this for instance.
		else
			playergui.ToolsGui.Enabled = false
		end
	else
		warn("Player has not loaded!")
	end
end

Yes I know, it’s such a simple piece of code, lmao.

Please help if you know!

Humanoid.Died is a event, you didn’t even Connect it :neutral_face: Also there’s no need to put it through a loop, as it’s more unnecessary

local player = game.Players.LocalPlayer
local playergui = player:WaitForChild("PlayerGui")
local char = player.Character or player.CharacterAdded:Wait()
local Humanoid = char:WaitForChild("Humanoid")

playergui.ToolsGui.Enabled = false
print("Player Character has been loaded!")

Humanoid.Died:Connect(function() --This will fire as soon as the Character's Humanoid Health reaches 0 or dies
    playergui.ToolsGui.Enabled = true
end)
1 Like