How do I make a cash on kill and earn different amounts of money for different swords and guns

I really need help this is the cherry to the cake for my game that sounded cheesy ignore that but I’ve made the cash on kill script My leader stat for money is coins anything could help thank you for spending your time and reading this

7 Likes

Please don’t duplicate posts! Also, could you provide more information?

What do you mean?

3 Likes

Ok sorry about the duplicate that’s a whole different story but basically I’m making a killing simulator I want to make it so if you have a gun you get 25 coins per kill and if you have the rocket launcher you get 50 coins per kill do you want me to add more info?

2 Likes

What have you tried? do you have any code to show us?

2 Likes

ok I have some code I had no hope in it at all So I didn’t try in it there’s so many things wrong in this code that’s why I’m looking for help poqimage

2 Likes

I think you just need to check the tag’s name. If it is a gun then award… If it is a rocket launcher then award…

2 Likes

ok how do I put that into script

1 Like

So, I am assuming there is a script that makes the leaderstats?

1 Like

Yes that script is in the workspace

1 Like

I’d insert that script into ServerScriptService if I was you.

Now, when you close off the function like this: game.Players.PlayerAdded:Connect(function(player)
and you press Enter, the script should automatically add the end) with the closing bracket. But your script does not.

1 Like

Try doing this: Make the gun create a value inside the enemy called like the player name and as value the exp gained value, if you re-hit and you find the value you don’t create it again but increase the value of it, make it so when the enemy dies the experience is given to the players that created a value inside it.

2 Likes

Base on your script(starting from the tag variable):

local tag = character.Humanoid:FindFirstChild("creator")
if tag ~= nil then
   local stats = tag.Value:WaitForChild("leaderstats")
   if tag.Value == "your gun name here" then
      stats["Coins"].Value = stats["Coins"].Value + -- your value here
   elseif tag.Value == "your other gun name here" then
      stats["Coins"].Value = stats["Coins"].Value + -- your value here
   end
end

This should work I think.

2 Likes

I copied and pasted a bit because it was in a local script and that format was stuffed for some reason

3 Likes

The script won’t work inside a localscript. Localscripts can do game.Players.PlayerAdded but you can’t set the coins in the client. Put it in a script inside ServerScriptService and put all the code in one script, since they server similar functions.

3 Likes

I’ll try it thanks so much for the help

2 Likes

ok I’ll retry it thank you :smiley: thanks so lich

2 Likes

Would I put the ID of the gun or the Name I’ll see what works but I think the is will work anyway thanks so much this helps me and my game so much I’ll try it out tomorrow. :slight_smile:

2 Likes

Ok thanks I’ll try that… I’m just doing dogs to make it longer so it wil let me type it because it’s to short

2 Likes

Didn’t work :frowning: thanks for helping anyway

4 Likes

I had the same problem and found no resolution

1 Like