How can you make an assist system?

How can I make an assist system where depending on how much money you deal to a certain NPC, you get a certain amount of money.

EX: Say if you did 50% of the damage to an NPC, it would give you 50% of the value you would get if you killed it by yourself.

It might have to do with creator tag or something. I made it where if 1 person gets the last hit, it gives them money.

I put a script into the NPC where it gave you a set amount of money when you killed them.

Are there ways to do this? I’ve seen many games with this concept and can’t figure it out.

2 Likes

Hi, i dont fully understand your question. You need to get % from number or you need understand who did last hit?

I don’t know if there’s a better way but according to me, i would create a intvalue instance manually added from the damage code, make a folder specifically named something then set the value instance’s parent in the folder.

I would only add that code when some sort of weapon damages a non-familiar NPC, it would run that code also adding the applied damage dealt.

Don’t forget to also rename the value’s name to the damage dealer when the value and the folder is added in by the way.

Now, if it’s the same NPC that took damage already, it adds the damage again, now i don’t know how you would do this but i’ll start with the NPC’s death.

Now, make sure the folder is located in the NPC that took damage which was created from the damage script, when the NPC dies, it would make an if statement if there is a exactly named user with that int value’s name. If it finds it using the “for i v” strat, you can use another one if it suits you more.

Anyways, if the player has a leader statistic, you can manage it so the amount of value the int value had, it would add to that leader statistic’s specific value. You should also divide it by the NPC’s health so the player doesn’t gain a lot of money extremely fast, don’t also forget to delete the folder within the value to avoid some strange bugs i didn’t know.

You should also mess with the math to see if it gets an accurate value to what you want it to get.

If I understand you correctly, this must be the solution:

local NPCHealth = 200
local Reward = 1000
local Players = {} -- Table with players who did damage

-- After players will defeat a NPC, table will looks like this: {{"Player1", 120},...} (First is player's name, second is player's damage he did) 

local function Reward()
	for _, PlayerTable in pairs(Players) do
		local Player = game.Players[PlayerTable[1]] -- Getting player
		local PlayerDamage = PlayerTable[2]/NPCHealth -- Matching in % how much player did damage (For Player1 it will be 120/200 = 0,6 (60%))
		local PlayerReward = Reward * PlayerDamage -- Matching how much gold player will get (for Player1 it will be 1000 * 0,6 = 600 Gold)

		Player.leaderstats.Gold.Value += PlayerReward -- Adding PlayerReward to his stats
	end
end

-- Remember that you somehow need to insert players' tables to Players

Reply me if I’m wrong

1 Like

okjsdfhjkl;okjolfeakjl;dfsl;km’fdssdfsdfSDFGSGDFGFSDGSFD

Something like that yes.

1 Like

Sorry I’m new, what do you mean by inserting players to tables?

2 Likes

Ohh, didn’t see your message. If you still need an answer, I mean table.insert()

1 Like