Humanoid.Died not activating

Hey,
I’ve got a local script and a server script, that detects when the player dies!
It isn’t working. I’m not getting any errors.

Local Script in StarterCharacterScripts

local Player = game.Players.LocalPlayer
local Events = game:GetService('ReplicatedStorage'):WaitForChild('Events')

Player.CharacterAdded:Connect(function(Character)
	local Humanoid = Character:WaitForChild('Humanoid')
	Humanoid.Died:Connect(function()
		if not Player:FindFirstChild('DogeTag') then
			Events.RemovePlayer:FireServer()
		end
	end)
end)

ServerScript ( in serverscriptservice)

Events.RemovePlayer.OnServerEvent:Connect(function(Player)
	if table.find(PlayingPlayers,Player) then
		if not Player:FindFirstChild('DogeTag') then
			Values.KillFeed.Value = Player.Name..' was killed by the Doge!'
			local ReturnValue = table.find(PlayingPlayers,Player)
			table.remove(PlayingPlayers,ReturnValue)
			wait(.5)
			print(#PlayingPlayers)
		end
	end	
end)

Thanks for any help! There are no errors.

I’m pretty sure a local script won’t run in StarterCharacterScripts but if that isn’t the reason then Humanoid.Died only fires if the humanoid is in the workspace.

2 Likes

Where should I put it then? In starterplayerscripts? And the humanoid is in Workspace.

Localscripts that are placed in StarterCharacterScripts do run, as they are added to the character model once they spawn.

1 Like

Can you add print statements in your code to see till where its running?

1 Like

I changed it to this:

local Player = game.Players.LocalPlayer
local Events = game:GetService('ReplicatedStorage'):WaitForChild('Events')

Player.CharacterAdded:Connect(function(Character)
	print('new character')
	local Humanoid = Character:WaitForChild('Humanoid')
	Humanoid.Died:Connect(function()
		print('Humanoid Died')
		if not Player:FindFirstChild('DogeTag') then
			Events.RemovePlayer:FireServer()
			print('fired event')
		end
	end)
end)

new character never prints, and died doesn’t print either.

I just realised you have a CharacterAdded event, in a script that is located in StarterCharacterScripts it won’t run as it will wait for the next CharacterAdded event, because that script is added just after character spawns.

What you need to do is just the following:

local Player = game.Players.LocalPlayer
local Events = game:GetService('ReplicatedStorage'):WaitForChild('Events')

local Humanoid = Player.Character:WaitForChild('Humanoid')

Humanoid.Died:Connect(function()
	print('Humanoid Died')
	if not Player:FindFirstChild('DogeTag') then
		Events.RemovePlayer:FireServer()
		print('fired event')
	end
end)

This happened to me, use Wait() instead of Connect(), it should work (It worked for me :/)

1 Like

I don’t see why you need a remote event for this. Can’t you just put it all in a Server script?

2 Likes

It looks like he is going to be documenting the death and updating the table as the game plays along, which seems like it would need a remote event but i’m not entirely sure because I’m not in proactive mode

1 Like

This is the condition he needs to fire an event. Which mean DogeTag is accessible from the client. But

he also checks it on the server which means it is also accessible by the server. And he just needs to put a CharacterAdded and Died event instead of the OnServerEvent. So I think this should work(Server script):

local players = game.Players

players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        character.Humanoid.Died:Connect(function()
             --rest of the code
        end)
    end)
end)
1 Like

Oh yes I am starting to think logicallly now. That does work, if it’s just in rep storage i believe

1 Like

I did put it in a ServerScript, but it didn’t work.
Script:

	Player.CharacterAdded:Connect(function(Character)
		print('new char')
		Character.Humanoid.Died:Connect(function()
			print('char')
			if not Player:FindFirstChild('DogeTag') then
				print('not doge')
				if table.find(PlayingPlayers,Player) then
					print('is playing')
					Values.KillFeed.Value = Player.Name..' was killed by the Doge!'
					local ReturnValue = table.find(PlayingPlayers,Player)
					table.remove(PlayingPlayers,ReturnValue)
				end
			end
		end)
	end)

It’s in a PlayerAdded Event.

Can you paste the full script please?

1 Like
Players.PlayerAdded:Connect(function(Player)
	
	local Leaderstats = Instance.new('Folder',Player)
	Leaderstats.Name = 'Leaderstats'
	
	local Gems = Instance.new('IntValue',Leaderstats)
	Gems.Name = 'Gems'
	Gems.Value = DefaultGemsValue
	
	local MapVoted = Instance.new('IntValue',Player)
	MapVoted.Name = 'MapVoted'
	
	local EquippedSkin = Instance.new('StringValue',Player)
	EquippedSkin.Name = 'EquippedSkin'
	EquippedSkin.Value = 'Default'
	
	local TrapCount = Instance.new('IntValue',Player)
	TrapCount.Name = 'TrapCount'
	TrapCount.Value = 5
	
	local EquippedTrap = Instance.new('StringValue',Player)
	EquippedTrap.Name = 'EquippedTrap'
	EquippedTrap.Value = 'Default'
	
	local TrapCount = Instance.new('IntValue',Player)
	TrapCount.Name = 'TrapCount'
	TrapCount.Value = 10
	
	local TrapDebounce = Instance.new('BoolValue',Player)
	TrapDebounce.Name = 'TrapDebounce'
	TrapDebounce.Value = false
	
	local SeenLuke = Instance.new('BoolValue',Player)
	SeenLuke.Name = 'SeenLuke'
	SeenLuke.Value = false
	
	local OwnedSkins = Instance.new('Folder',Player)
	OwnedSkins.Name = 'OwnedSkins'
	
	local DefaultSkin = Instance.new('StringValue',OwnedSkins)
	DefaultSkin.Name = 'Default'
	
	local OwnedTraps = Instance.new('Folder',Player)
	OwnedTraps.Name = 'OwnedTraps'
	
	local DefaultTrap = Instance.new('StringValue',OwnedTraps)
	DefaultTrap.Name = 'Default'
	
	local OwnedGears = Instance.new('Folder',Player)
	OwnedGears.Name = 'OwnedGears'
	
	local EquippedGear = Instance.new('StringValue',Player)
	EquippedGear.Name = 'EquippedGear'
	EquippedGear.Value = 'Default'
	
	local DefaultGear = Instance.new('StringValue',OwnedGears)
	DefaultGear.Name = 'Default'
	
	
	

	
	local GemsStore,EquippedSkinStore,EquippedTrapStore,SeenLukeStore,EquippedGearStore
	
	local savedSkins = skinsDS:GetAsync(Player.UserId) or {}
	local savedTraps = trapsDS:GetAsync(Player.UserId) or {}
	local savedGears = gearsDS:GetAsync(Player.UserId) or {}
	
	local Success, ErrorMessage = pcall(function()
		GemsStore = dStore:GetAsync(Player.UserId.."Gems")
		EquippedSkinStore = dStore:GetAsync(Player.UserId..'EquippedSkin')
		EquippedTrapStore = dStore:GetAsync(Player.UserId..'EquippedTrap')
		SeenLukeStore = dStore:GetAsync(Player.UserId..'SeenLuke')
		EquippedGearStore = dStore:GetAsync(Player.UserId..'EquippedGear')
	end)
	
	if not Success then
		warn('An error occured while getting '..Player.Name..'\'s data: '..ErrorMessage)
	end
	
	if GemsStore ~= nil then
		Player.Leaderstats.Gems.Value = GemsStore
	end
	
	if EquippedSkinStore ~= nil then
		Player:WaitForChild('EquippedSkin').Value = EquippedSkinStore
	end
	
	if EquippedTrapStore ~= nil then
		Player.EquippedTrap.Value = EquippedTrapStore
	end
	
	if EquippedGearStore ~= nil then
		Player.EquippedGear.Value = EquippedGearStore
	end
	
	if SeenLukeStore ~= nil then
		Player.SeenLuke.Value = SeenLukeStore
	end
	
	for i, SavedSkin in pairs(savedSkins) do
		local Skin = Instance.new('StringValue',Player.OwnedSkins)
		Skin.Name = SavedSkin
		wait()
		game.ReplicatedStorage.Events.UpdateBackpack:FireClient(Player,SavedSkin)
	end
	
	for i, SavedTrap in pairs(savedTraps) do
		local Trap = Instance.new('StringValue',Player.OwnedTraps)
		Trap.Name = SavedTrap
		wait()
		game.ReplicatedStorage.Events.UpdateBackpack:FireClient(Player,SavedTrap)
	end
	
	for _, SavedGear in pairs(savedGears) do
		local Gear = Instance.new('StringValue',Player.OwnedGears)
		Gear.Name = SavedGear
		wait()
		game.ReplicatedStorage.Events.UpdateBackpack:FireClient(Player,SavedGear)
	end
	
	if MarketplaceService:UserOwnsGamePassAsync(Player.UserId,10647364) then
		Events.DogeChance:FireClient(Player,'50')
	else
		Events.DogeChance:FireClient(Player,'10')
	end
	
	Player.CharacterAdded:Connect(function(Character)
		print('new char')
		Character.Humanoid.Died:Connect(function()
			print('char')
			if not Player:FindFirstChild('DogeTag') then
				print('not doge')
				if table.find(PlayingPlayers,Player) then
					print('is playing')
					Values.KillFeed.Value = Player.Name..' was killed by the Doge!'
					local ReturnValue = table.find(PlayingPlayers,Player)
					table.remove(PlayingPlayers,ReturnValue)
				end
			end
		end)
	end)

	
	
end)

Can you check till where it is running, i mean like checking till which print its running.

New char prints but only for the Doge(his character gets changed). New Char doesn’t print for the other players when they join.

Character added is never called because the character has already been added by the time the script runs.

1 Like

Should I do this instead?

local Character = Player.Character or Player.CharacterAdded:Wait()

Well, now I have another problem, if the character dies, the second time it doesn’t work!
How can I fix this?