NPC Percentage Value on NPC Kill

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    So i have this script and it gives souls based on percentage damage so for example if you do 90% dmg and someone else does 10% he gets 10% souls and you get 90% but the problem i have is if someone else does 90% dmg and you do 1000% dmg let say you will get 200 Souls (thats how much the entire npcs gives 100%) and the other player will get 180. I want to somehow make it so even if u deal 1000% dmg u will get the remainder of the percentage basically 10% not 100% this is my code right now :
  2. What is the issue? Include screenshots / videos if possible!
    /
    |
    |
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local Mob = script.Parent
local Humanoid = Mob:WaitForChild("Zombie")


local PercentReq = 1 -- Has to do at least 10% of Damage 

Humanoid.Died:Connect(function()
	for i,v in pairs(Humanoid:GetChildren()) do
		if string.sub(v.Name,1,6) == "HitBy:" then
			spawn(function()
				print("Getting Percentage")
				local Percentage = (v.Value/Humanoid.MaxHealth)*100
				if Percentage >= PercentReq then
					print("Getting Character")
					local Char = game.Workspace:FindFirstChild(string.sub(v.Name,7))
					if Char then
						print("Getting Player")
						local Player = game.Players:GetPlayerFromCharacter(Char)
						if Player then
							print("Getting Stats")
							local stats = Player:FindFirstChild("leaderstats")
							local killedbandits = Player:FindFirstChild("killedbandits")
							if stats then
								print("Getting Coins")
								local coins = stats:FindFirstChild("Souls")
								if coins then
									if v.Value >= 100 then
										coins.Value = coins.Value + 100 * 2
										print("Gave "..Player.Name.." "..(100 * 2).." Coins")
										print(Player.Name.." Did "..Percentage.."% Damage")
										if killedbandits then
											killedbandits.Value = killedbandits.Value + 1
										end
									else
										coins.Value = coins.Value + Percentage * 2
										print("Gave "..Player.Name.." "..(Percentage*2).." Coins")
										print(Player.Name.." Did "..Percentage.."% Damage")
										if killedbandits then
											killedbandits.Value = killedbandits.Value + 1
										end
									end
								else
									warn(Player.Name.." Coins Not Loaded")
								end
							else
								warn(Player.Name.." Stats Not Loaded")
							end
						else
							warn(Char.Name.." Not Found In Players")
						end
					end
				else
					print("Not Enough Damage..."..string.sub(v.Name,7).." Only did "..Percentage.."% Damage")
				end
			end)
		end
	end 
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like

I guess you could create a variable called total money and set that to however much the bandit is supposed to give and when players are awarded coins for damage you subtract how much they got from the total money, and if the players then does a higher percentage than the mob has health remaining and they are supposed to get 100% of the coins check if that many coins is in total coins and if it’s not give them the rest of the total coins amount instead.

1 Like

Maybe i could do something like MaxCoins/Percentage but i need to first make sure to get the right percentage hopefully i can figure it out tomorrow when i wake up