Function inside Humanoid.Died not running

My humanoid.died event is running fine, but the function called inside of it is not. Here is my code (it is a localscript inside of StarterCharacterScripts):

local function OnReset(CurrentStage)
	
	print("Called OnReset")
	
	Character = Player.CharacterAdded:Wait()
	Humanoid = Character:WaitForChild("Humanoid")
	Character.PrimaryPart = Character:WaitForChild("HumanoidRootPart")

	Character:SetPrimaryPartCFrame(workspace.SpawnPoints:FindFirstChild("SpawnPoint"..CurrentStage).CFrame)
	
end

Humanoid.Died:Connect(function()

	print("Died")

	local RequestStage = RepStore:FindFirstChild("RequestStage")

	local CurrentStage = RequestStage:InvokeServer()

	OnReset(CurrentStage)

end)

The output only says “Died”. Any and all help is appreciated!

Not sure, but I believe you need to call the OnReset local function once to test that it works?

Try this:

local function OnReset(CurrentStage)

	if not CurrentStage then
        return
    end
	print("Called OnReset")
	
	Character = Player.CharacterAdded:Wait()
	Humanoid = Character:WaitForChild("Humanoid")
	Character.PrimaryPart = Character:WaitForChild("HumanoidRootPart")

	Character:SetPrimaryPartCFrame(workspace.SpawnPoints:FindFirstChild("SpawnPoint"..CurrentStage).CFrame)
	
end

Humanoid.Died:Connect(function()

	print("Died")

	local RequestStage = RepStore:FindFirstChild("RequestStage")

	local CurrentStage = RequestStage:InvokeServer()

	OnReset(CurrentStage)

end)

OnReset(nil)
1 Like

It is calling every time the player resets, but that’s because StarterCharacterScripts are reset everytime the player dies. However, I realized Humanoid.died might not be necessary since I can just call this function in the script, and it will be called every time the player resets. Thanks!