Kill Detection - How can this be done?

Aight. So basically, I want to detect who killed who, and reward the killer with some cash. I don’t have anything so far as I have no idea where to start. I am also not sure whether to do this in my leaderstats script or the sword script (the sword aint mine / its a free model)

My leaderstats code:

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local DeathCount = Instance.new("IntValue")
	DeathCount.Value = 0
	DeathCount.Name = "Deaths"
	DeathCount.Parent = leaderstats

	local Cash = Instance.new("IntValue")
	Cash.Name = "Cash"
	Cash.Value = 100
	Cash.Parent = leaderstats


	player.CharacterAdded:Connect(function(char)
		local humanoid = char:WaitForChild('Humanoid')
		humanoid.Died:Connect(function()
			Cash.Value = Cash.Value + 50
			DeathCount.Value = DeathCount.Value + 1
			
			-- Detection
			
		end)
	end)
	
	
end)

Cheers.

1 Like

You can create a “creator” ObjectValue and parent it to the victim’s Humanoid in your weapons code when damaging, cleaning the creator value up after 5 seconds.

Then in your Died connection, you could check if a creator was in the dying Humanoid and get the value if it was. The value of creator should be the killer and you can do whatever you need with that.

In the future, it would be best if you looked up the answer to your problem before making a post about it because there are a few posts on this sort of thing:

3 Likes

Alrighty. I will try that, but if I need guidance along the way, are you willing to assist me?

1 Like

The first reply of the first post I’ve listed provides some code samples for tagging humanoids with ObjectValues.
If you need anymore help beyond that, I’ll try my best.

2 Likes