Leaderstats script that doesn't work

Hello Developers!
I have a game with leaderstats of kill for money
But I have a problem, When someone kill me I get the money and not him

I need your help by giving me a feedback on the leaderstats script

  • Check the script and tell me what the problem is.
  • Tell me what needs to be changed in the script for it to work properly.

The script:

 local folder = Instance.new("Folder",player)
 folder.Name = "leaderstats"
 local currency1 = Instance.new("IntValue",folder)
 currency1.Name = "Money"
  local tag = character.Humanoid:FindFirstChild("creator")
   if tag ~= nil then
    if tag.Value ~= nil then
     currency1.Value = currency1.Value + 10 --This is the reward after the player died.

good luck! :smiley:

Your script is checking if the character died and if it did, it adds currency to it.

What I would do is check the character from the weapon and continue from there.


if hit.Parent.Humanoid.Health == 0 then
	player.currency1.Value = player.currency1.Value + 1
1 Like

Wouldn’t it be a better idea to find the player through the ‘creator’ tag? If I remember correctly, you should store the name of the player in the ‘creator’ value so you can determine the player. From there, navigate to that player’s ‘Money’ ValueObject and from there, you can change it. In your script, you aren’t showing that you’re actually retrieving the player from the creator tag, so that’s why I’m fairly confused how you’re determining who the killer was.

OT: This belongs in #help-and-feedback:scripting-support as it’s a help request. #help-and-feedback:code-review is for (as the title implies) getting others to review & suggest improvements to your code.

Thank you so much @SpartaBon for solving this problem from your feedback. Now when someone kill me he gets the money thank you for your feedback! :smiley:


player.currency1.Value = player.currency1.Value + 1


player.currency1.Value += 1