Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I make a character gain exp when another character kills them?

Asked by
Qiuor 20
8 years ago

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

Log in to vote
2
Answered by 8 years ago
Edited 8 years ago

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 :)

0
Where would I put the script? inside of the player? Qiuor 20 — 8y
0
No, you'd put it in the handle of a tool, like a sword DepressionSensei 315 — 8y
Ad

Answer this question