How would I make a coins per hit system?

I have a Boss system but now I ran into another problem. How would I make a coins/cash per hit system, that gives coins each hit on the NPC/Boss? :confused:

I would greatly appreciate help :slight_smile:

Here is an example:

I tried my best searching for tutorials or people talking about it but nothing :confused:

4 Likes

You would just give the coin when you damage the boss/NPC.
And here is a simple script that would increase the player currency.

local currencyName = "Coin"
local coinsPerHit = 2 -- 2 coins would be given when hit the boss/NPC
local plr = nil -- i am not gonna define the player since i dont know what script you are gonna put it into.

plr.leaderstats[currencyName].Value = plr.leaderstats[currencyName].Value + coinsPerHit
5 Likes

How would I make it so it only gives the coins when the boss is defeated? Sry for too many questions.

Just save how many hits the player did, then award them when the humanoid of the enemy dies using Humanoid.Died

3 Likes
if boss.health = 0 then --or nil
-give player coins
end
2 Likes

You can do this easily with few steps

The Steps are:

  • Store Player’s name when they hit boss
  • Store Player’s data. How much they get from boss
  • Reward Player after boss die
  • Clear the Storage. Ex // Player’s Name and Player’s Money after the boss die

You can search people video for the tutorial
Like this Guy
You can use Table or Folder to Store Player’s name and data

2 Likes

I have a quick question would i need to save the data or just store it?

It’s up to you, But I recommended to store data because Data Saving and Data Loading are Confusing for newbie like you or not.

yea I mean I arleady have engough data to save, I dont really want to trigger a “data was added to que” error.

btw sry for my spelling i am not native xD

@Tonnumkung4 Wait do you mean like ordered data stores?

No, If you are using Table to store player’s name and money You just use table.insert().
but If You are using Folder to Store player’s name and money. You just add a string value that tell player’s name and player’s money that they get from boss.

I just whatched the tutorial you linked to me but i dont really know how would i implement this on my npc/Boss :confused:

Try the new one. I’ve updated it

Yea, This topic has a really long comments.

1 Like

k I will try the new one you gave me.

alr this helped me a lot but how will I make for the hits? Like each time you hit the boss wich i think you would do an onTouched event I want to add 1 to hits

onTouched Event with a Debounce, probably.

1 Like

for the hits would I need to add 1 to hits each time a touch event is triggered with the sword. But how will I implement this on other players with a gamepass x2 coins? :confused: this is harder than what I thought xD

You can check if he has the gamepass with
local doesOwn = game:GetService("MarketPlaceService"):UserOwnsGamepassAsync(userId, gamePassId)