NPC Reward on 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 a script that gives you Souls depending on how much % damage you did and it works for multiple people so if u did 90% dmg u get 90% Value and the other person gets 10%. This script only works if you do the damage with Melee Weapons such as swords. I have a ranged weapon and i want it to work for it too. Idk how exactly local Tag = Humanoid:FindFirstChild(“creator”) somehow has to be implemented in the script.
  2. What is the issue? Include screenshots / videos if possible!
    Explained Above
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve looked for this topic and couldn’t find anything similar

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("Humanoid")


local PercentReq = 10 -- 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")
                            if stats then
                                print("Getting Coins")
                                local coins = stats:FindFirstChild("Souls")
                                if coins then
                                    coins.Value = coins.Value + Percentage * 2
                                    print("Gave "..Player.Name.." "..(Percentage*2).." Coins")
                                    print(Player.Name.." Did "..Percentage.."% Damage")
                                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.