i have a code that give a player 'xp' when he kill an npc, but if 2 players damage the npc only the player who killed the npc will take the 'xp', so i want a way to give the player who does the most damage to the npc to take the 'xp' can any one help ?
this is the NPC script:
local humaniod = script.Parent:WaitForChild("Humanoid")
humaniod.Died:Connect(function()
game.ServerStorage.Give:Fire(5, humaniod.creator.Value)
end)
and this is the script in the ServerScriptService :
game.Players.PlayerAdded:connect(function(player)
local info = Instance.new("Folder", player)
info.Name = "playerInfo"
local xp = Instance.new("IntValue",info)
xp.Name = "XP"
xp.Value = 0
game.ServerStorage.Give.Event:Connect(function(xpAmount, plr)
if plr.Name == player.Name then
xp.Value = xp.Value + xpAmount
end
end)
end)
