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 make a character gain exp when another character kills them?

so how would I get a player to gain exp when they kill another player? I understand how leaderstats work just not how the function would work.

1 answer

The best way to create a function that does something upon a death is by using the .Died event of a Humanoid. How this event works is that when a Humanoid dies, the function is carried out. To create a function that would give a player EXP once he killed another player, you'd do something like this:

script.Parent.Touched:connect(function(touched) --In this case the parent of the script is a tool
	if touched.Parent.Humanoid then  --Script checks to see if it is a human
		touched.Parent.Humanoid:TakeDamage(10)
		if touched.Parent.Humanoid.Health == 0 then --If the opponent who was hit was killed then this will run
			script.Parent.Parent.EXP = script.Parent.Parent.EXP + 1 --Adds EXP
		end
	end
end)

If this helped you, please don't forget to accept the answer :)

2 comments

0

Where would I put the script? inside of the player?

0

No, you'd put it in the handle of a tool, like a sword

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