If you have a damage system and you can track how much damage each player dealt, then you have to calculate the percentage by dividing all of the enemy dealt damage by enemy HP. After finding the ratio(it might look like 0.2 as in 20% of damage done by the player) what is left is to specify the max winning amount and calculate the percentage of winnings to be given to a certain player. Example: if player dealt 40% of damage or 0.4 and max winnings are 1000$ then 1000 * 0.4 is 400$ - final winnings. Other player who dealt 0.6 of damage (since 1 - 0.4 is 0.6) will receive 600$.
If the boss has a humanoid you can track when it dies.
When a player does damage do: bossHumanoid:SetAttribute(attacker.Name, numDamage)
You should make a conditional statement that checks if the boss humanoid already has damage from a certain player, and if it does, just take their existing damage and add more.
After the boss humanoid dies, you would check the values.
local humAttributes = bossHumanoid:GetAttributes()
for playerName, dmg in pairs(humAttributes) do
print(playerName.." did "..dmg.." damage!")
-- Here you would do your percentage calculations local reward = dmg / bossReward
end
if Humanoid:GetAttribute(Player.name) then
local Attribute = Humanoid:GetAttribute(Player.name)
Humanoid:SetAttribute(Player.name, Attribute + 12)
else
Humanoid:SetAttribute(Player.name, 12)
end
it does work, although one problem i have is that it sometimes goes over the health,
As in ill kill the enemy and the attribute says ive done 108 damage but the humanoid had only 100 hp
dont know what i can do to fix this
This should clamp the damage so that it can’t exceed 100. If your boss has more than 100 hp you can simply set 100 to bossHumanoid.MaxHealth
You should also add a conditional statement in your damage code.
local curHealth = bossHumanoid.Health -- health BEFORE you damage the boss
if rawDamage > curHealth then -- if this is the final blow that kills the boss:
local Attribute = Humanoid:GetAttribute(Player.name)
local trueDamage = rawDamage - curHealth
Humanoid:SetAttribute(Player.name, Attribute + trueDamage)
end
Whenever a player damages a boss, log their damage into a counter, preferably in a dictionary or in anyway you use to keep track of damage, add their damage to a total. Then, when the boss dies, use this formula to get the percent of how many players did damage;
local PercentOfDamage = (playerDamage / BossTotalHp) * 100
After you have the percent, multiply that percent number by 100 for the reward
local reward = PercentOfDamage * 100
This is only the code i understood to make from your description, so you will need to modify it if needed