Humanoid.Died fails to detect a player's Reset Character

Very simple and will get straight to the point.
I have a script that detects when a player dies.
When a player dies from an object or entity that depletes their health, the function is called.
However, if the player were to manually press the Reset Character button to die, the script fails to call itself. As if it’s undetected. Is this a bug? Is it just something Humanoid.Died doesn’t detect? If so, are their any alternative methods I could use to detect when a player has died AND reset?

My code:

game.Players.CharacterAutoLoads = false --disables players respawning
local DataStoreService = game:GetService("DataStoreService")
local HelpfulFunctions = require(game.ServerScriptService.HelpfulFunctions)

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		Character.Humanoid.Died:Connect(function()
			local Essentials = Player:FindFirstChild("Essentials") --Folder inside player with certain values
			if Essentials then
				Essentials.Misc.Alive.Value = false --Changing to false activates a gameover screen.
				Essentials.Stats.Deaths.Value += 1
				HelpfulFunctions.SaveStats(Player) --Saves data.
			end
		end)
	end)
	Player:LoadCharacter()--spawns player
end)

Any help would be greatly appreciated. Thanks!

1 Like

I am not sure what the problem is, I put this script in ServerScriptService though and it worked when it reset. Try putting the script in ServerScriptService if it is not already and it might work

game.Players.CharacterAutoLoads = false --disables players respawning

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		Character.Humanoid.Died:Connect(function()
			print("it worked")
		end)
	end)
	Player:LoadCharacter()--spawns player
end)

If it is, try making it so if the essentials folder doesn’t exist print something to see if the folder somehow deletes on a reset, the function may be called but you can’t tell because of the essentials folder deleting.

2 Likes

If died doesn’t work how about checking if humanoid health <= 0 with humanoid.HealthChanged event ?

1 Like

The best method you can use to detect when a player resets is by doing this (LocalScript in StarterPlayerScripts):

local StarterGui = game:GetService("StarterGui")

local bindableEvent = Instance.new("BindableEvent")

local function onResetButtonCallback()
	-- Run the code you want to happen when a player resets here, example:
	print(true)
end

local function setResetButtonCallback()
	local success = pcall(StarterGui.SetCore, StarterGui, "ResetButtonCallback", bindableEvent)

	if success then
		bindableEvent.Event:Connect(onResetButtonCallback)
	return end

	task.delay(0, setResetButtonCallback)
end

setResetButtonCallback()

Although do note that by using this method you’ll need to use a RemoteEvent to kill the player on the server-side afterwards since it removes the death caused by the reset button, but this isn’t a hard problem to fix really and I’m willing to help provide an example if necessary

2 Likes