Help with assist system

I’m making an assist system where when you hit an npc you get a percentage of the full reward if you killed it by yourself. Say an npc had 100 health and i did 50 damage to it, i would get 50% of the reward.

This is my script as of now:

local Reward = 25
local Players = {{“p_pof”,80},{“p_pof”,20}} – Table with players who did damage

local function RewardingPlayer()

for _, PlayerTable in pairs(Players) do
	print(PlayerTable)
	local Player = game.Players[PlayerTable[1]] -- Getting player
	--if PlayerTable[2] < Humanoid.MaxHealth then
	local PlayerDamage = PlayerTable[2]/Humanoid.MaxHealth
	local PlayerReward = Reward * PlayerDamage
	
	print(Player)

	Player.leaderstats.Nooblets.Value = Player.leaderstats.Nooblets.Value + PlayerReward 
	game.ServerScriptService.NoobletsScript.Add:Invoke(Player, PlayerReward)
	--end
end

end

Humanoid.HealthChanged:Connect(function()

local tag = Humanoid:findFirstChild("creator") 
if tag ~= nil then 
	if tag.Value ~= nil then 
		
		
		
		
		
		end
	end

end)

My problem is that I’m not sure how to insert a table with the player’s name and the amount of damage they’ve done. Any help on this would be appreciated. I’m also wondering if this script could be improved.

thanks!

1 Like

script starts at local Reward and ends at “end)”

1 Like

For future reference, you can edit your posts.

You can use table.insert to add a table, to a table. For example:

table.insert(Players,{PlayerWhoHit.Name,DamageDealt})

Ide keep track of damage inside whatever script is damaging the humanoid in the first place. Modules are good for that, if your storing one global assist table.

Also, your scripts are pretty solid. Good work on that.

1 Like

I would recommend checking the Humanoid’s State.
Use Humanoid.HealthChanged**. If the Humanoid isn’t dead, then the last player responsible for the damage of the Humanoid should be marked under a temporary local variable.

I’m not much a fan of the way you’ve attempted to do this so I would recommend using a module or damage function that supports the inclusiveness of an attacker & target.