Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How would i detect a player if they killed another player?

Basically, the concept is this. Player kills other player Player gains xp as well as money.

This is a follow up to a very old question i made a few years back. Though i still have the the old lines of code, it would be way too hard trying to look back and finding it. i hope you guys understand where im coming from..

1 answer

Okay. Let's make a leaderboard stat called XP. We can do this with this script

game.Players.PlayerAdded:connect(function(player)
	local folder = Instance.new("Folder",player)
	folder.Name = "leaderstats"
	local stat = Instance.new("IntValue",folder)
	stat.Name = "XP"
end)

Now once a player joins, he has a leaderboard stat named XP. The following script will award the killer with XP if he has killed someone by using the Humanoid's "Died" event.

player.CharacterAdded:connect(function(character)
	character:WaitForChild("Humanoid").Died:connect(function()
		local tag = character.Humanoid:FindFirstChild("creator")
		if tag ~= nil then
			 if tag.Value ~= nil then
				 stat.Value = stat.Value + 10 --This is the reward after the player has been killed. 
				end
			end
		end)
	end)

You can keep the scripts separate for simplicity, or just have both of them in one script.

1 comment

0

Oh, I didn't even notice you said money as well... But same concept applies, create another Integer Value in the folder named Money/Cash/Whatever you'd like and add to it once they are killed.

This discussion is preserved as it was. New answers, comments, and votes are closed.