players.PlayerAdded:connect(function(player) --  player added
	player.CharacterAdded:connect(function(Character) -- character added
		humanoid = Character:WaitForChild("Humanoid") -- set humanoid
		humanoid.Died:Connect(function()
			if Humanoid:FindFirstChild("creator") ~= nil then 
				local killer = Humanoid.creator.Value
				killer.leaderstats.XP.Value = killer.leaderstats.XP.Value + 10
				local plrKilled = RS.Killed:Clone()
				plrKilled.Parent = killer.PlayerGui
				plrKilled.Frame.TextLabel.Text = "You killed " .. humanoid.Parent.Name .. " (+10 XP)"
				wait(2)
				plrKilled:Remove()
			end
		end)
	end)
end)

This script does work as expected, however, if you die, you have to kill two people until it pops up. Can someone tell me why?

13 comments

0

also this script is in ServerScriptService

0

dont use creator values

0

what then?

0

kill detection should be done after adding the damage to the humanoid

0

Also do not use Remove use Destroy

0

@kingdom5 i don't understand what you mean by "after adding the damage to the humanoid"

0

check if the damage done to the humanoid killed the player

0

then reward the player

0

@EXpodo1234ALT isnt that what humanoid.Died:Connect(function() is doing?

0

yes

0

so then what is my problem?

0

the problem is this event has no knowledge of the player doing the damage. It is far better to check while doing the damage as this code knows who is doing the damage.

0

Thank you. I don't really understand how i can add this into an event though?