Good day i am started before a few days whit Core, and i made a Save / XP System whit the help of a few Youtube Videos its Ads Xp when i kill somony(In Script Makerd whit --------------------------------------)For Scipt See down bellow. But i want to add xp to the player when its kill a mob i made the mobs whit NPC AI KIT from Comunity Content.
What can i do to make this?
Thanks to all in advance.
"""
function OnPlayerJoined(player)
local data = Storage.GetPlayerData(player)
local xp = data["xp"] or 0
local level = data["level"] or 1
local reqxp = data["reqxp"] or 120
reqxp = 100 * 1.20 ^ level
reqxp = CoreMath.Round(reqxp)
player:SetResources("xp", xp)
player:SetResources("level", level)
player:SetResources("reqxp", reqxp)
player.diedEvent:Connect(OnPlayerDied)
player.resourceChangedEvent:Connect(OnResourceChanged)
end
function OnPlayerDied(player, dmg)
player:RemoveResources("xp", 1)
local playerNewXp = player:GetResource("xp")
print(tostring(killerNewXp) .. " " .. dmg.sourcePlayer.name)
if Object.IsValid(dmg.sourcePlayer) then
dmg.sourcePlayer:AddResources("xp", 10)
local killerNewXp = dmg.sourcePlayer:GetResource("xp")
print(tostring(killerNewXp) .. " " .. dmg.sourcePlayer.name)
end
end
function OnDataSave(player)
local data = Storage.GetPlayerData(player)
local res = player:GetResources()
for key, value in pair(res) do
if key == "xp" then
data[key] = value
elseif key == "level" then
data[key] = value
elseif key == "reqxp" then
data[key] = value
end
end
function OnResourceChanged(player, resName, resValue)
Task.wait(0.1)
if (resName == "xp") then
local data = Storage.GetPlayerData(player)
local xp = resValue
local level = player:GetResources("level")
local reqxp = 100 * 1.20 ^ level
reqxp = CoreMath.Round(reqxp)
print(player.name .. level)
print(reqxp .. " " .. level)
if xp >= reqxp then
local xp = xp - reqxp
level = level +1
print(player.name .. level)
local reqxp = 100 * 1.20 ^ level
reqxp = CoreMath.Round(reqxp)
print(reqxp .. " " .. level)
player:SetResource("xp", xp)
player:SetResource("level", level)
player:SetResource("reqxp", reqxp)
end
end
end
Game.playerJoinedEvent:Connect(OnPlayerJoined)
Game.playerLeftEvent:Connect(OnDataSave)
"""