Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to add function add EXP when NPC is killed?

Asked by 3 years ago

Can anyone help me with an EXP script? I am trying to make is so that when i kill an NPC I will get EXP. for now it only gives money and kills. (i didnt script EXP in the leaderstats) this is the script im using:

local Humanoid = script.Parent.Humanoid
function addvalues() 
local tag = Humanoid:findFirstChild("creator") 
if tag ~= nil then 
if tag.Value ~= nil then 
local Leaderstats = tag.Value:findFirstChild("leaderstats") 
if Leaderstats ~= nil then 
Leaderstats.Zims.Value = Leaderstats.Zims.Value + 250 --Change Money to the stat that is increased.
Leaderstats.Kills.Value = Leaderstats.Kills.Value + 1 --Change Money to the stat that is increased. 


wait(0.1) 
script:remove() 
end 
end 
end 
end 
Humanoid.Died:connect(addvalues)


and this is the EXP script

game.Players.PlayerAdded:Connect(function(player)
    local level = Instance.new("IntValue", player)
    level.Name = "Level"
    level.Value = 1

    local exp = Instance.new("IntValue", level)
    exp.Name = "Current"
    exp.Value = 0

    local maxExp = Instance.new("IntValue", level)
    maxExp.Name = "Max"
    maxExp.Value = 100


    exp.Changed:Connect(function(val)
        if exp.Value >= maxExp.Value then
            -- Do stuff.

            level.Value = level.Value + 1
            exp.Value = 0
            maxExp.Value = maxExp.Value * 1.25
        end
    end)
end)

workspace:WaitForChild("GiveEXP").ClickDetector.MouseClick:Connect(function(player)
    player.Level.Current.Value = player.Level.Current.Value + 25
0
well in theory, the only way for this to work is if you manually code it within the weapon kkfilms_1 68 — 3y

Answer this question