Humanoid.Died did not work

Did it work once? I see why it didn’t work more than once and thats my bad, here’s the updated script:

game.Players.PlayerAdded:Connect(function(player) --Creating leaderstats: as before
	local leaderstats = Instance.new("Folder",player)
	leaderstats.Name = "leaderstats"

	local XP = Instance.new("IntValue",leaderstats)
	XP.Name = "XP"



	while true do --Character load
		if player.Character ~= nil then break
		end
		wait(5)
	end

	leaderstats.Parent = player

	local function getEnemy(humanoid) --Finding the enemy
		local Swordtag = humanoid:FindFirstChild("creator") ---Getting the tag the default sword adds
		if Swordtag ~= nil then
			local enemy = Swordtag.Value
			if enemy.Parent ~= nil then
				return enemy --Getting enemy to add XP in died event
			end
		end
		return nil
	end
	
	local function playerDied(humanoid, player)
		local killer = getEnemy(humanoid)
		if killer ~= nil then
			local leaderstats = killer:FindFirstChild("leaderstats")
			if leaderstats ~= nil then
				local enemyxp = leaderstats:FindFirstChild("XP")
				if killer ~= player then
					enemyxp.Value = enemyxp.Value + 1 --Giving enemy XP
				else
					--
				end
			end
		end
	end

	local humanoid = player.Character:WaitForChild("Humanoid")
	humanoid.Died:connect(function() --When player dies
		playerDied(humanoid, player)
	end)
	
	player.Changed:connect(function(prop) --When a player respawns we want to watch for .Died again
		if prop == "Character" and player.Character ~= nil then
			local humanoid = player.Character.Humanoid
			local plr = player
			local hum = humanoid
			humanoid.Died:connect(function()
				playerDied(hum, plr)
			end)	
		end
	end)
	
	
end)

Just had to add something in so that after a player respawns it would continue to run the died event for their new/respawned character.
Edit: This works perfectly for me using the default/Roblox sword model.

nope this script doesn’t even give player XP

It gives the enemy XP for killing someone with the sword… that is what you wanted, right? Are you seeing any errors? Or what exactly is your issue, because this script works perfectly fine for me in studio.

yes that’s what I wanted, the first I put it there is an error telling me you forget to put an end, but after I put the end, it still doesn’t work.

I’m also teaching my friend how to script right now, so maybe later I’ll try your new script out

The code in the message above works perfectly fine, it just needs to be a ServerScript and placed in ServerScriptService. It should also take the place of your existing ServerScript. This will be my 3rd time testing it with an in-studio play test so I know it is working code.

nope, it doesn’t work, Idk why

I put it inside of Server Script Storage, and it is a script

Can you send an image of the script and it’s location from the explorer? The script does work, there must be an error on your end. Have you made any changes to the default Roblox sword script?

not rlly, I just change the seconds that the tag will last for

I don’t think there is any error on my game, since i was just a baseplate and I’m just testing on that game

I have had issues with humanoid.died for forever, my advice is to just check if the health of the enemy is 0 and then give the XP. The result is the same.

The game for some reason can’t even detect that the enemy is dead

I also script that if the enemy’s is lower than 0, it will change back to 0

Try readding the sword from the toolbox and try again. If you’re testing in game make sure you’ve properly published to the place you’re testing in. Edit; and can you please send the pictures of the location?

k I will but because I have a crappy laptop the resolution is going to be bad


This is the place where the enemy and the XP system script is, and for the sword it is in Starter Pack

And are the contents of that script the code from this message, Humanoid.Died did not work - #21 by Jacko_Korbius , and that code only?

yes, it was that code only, and I need to extend this message or else roblox won’t let me send this

Then I’m not sure why it doesn’t work for you, it works for me just fine. If you’re continuing to test in studio, try testing in-game rather than the studio test and/or restarting studio.

Other than that, I guess you could use the Humanoid | Roblox Creator Documentation event but if the died event doesn’t work I don’t see why this would. It might be best to contact someone at Roblox that can better look into the issue.