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

Level leaderstat script not working?

Asked by 8 years ago

So I made this level leaderstat script for my roleplaying game that is supposed to work so that players can level up once they reach a certain value of XP. I used my gold leaderstat script and changed the names and values. The script overwrites my gold script and it doesn't work. Here are all the scripts.

Level leaderstat script:

local save = true 
local datastore = game:GetService("DataStoreService"):GetDataStore("Stats")
local ver = "V0.1"

game.Players.PlayerAdded:connect(function(join)

    local stats = Instance.new('IntValue')
    stats.Name = "leaderstats"
    stats.Parent = join

    level = Instance.new('IntValue')
    level.Name = "Level"
    level.Parent = stats

    if save == true then

        level.Value = datastore:GetAsync("Level"..join.Name) 
    end
end)

game.Players.PlayerRemoving:connect(function(leave)
    if save == true then

        datastore:SetAsync("Level"..leave.Name, level.Value)
    end
end)

Gold leaderstat script:

local save = true
local datastore = game:GetService("DataStoreService"):GetDataStore("Stats")
local ver = "V0.1"

game.Players.PlayerAdded:connect(function(join)

    local stats = Instance.new('IntValue')
    stats.Name = "leaderstats"
    stats.Parent = join

    cash = Instance.new('IntValue')
    cash.Name = "Gold"
    cash.Parent = stats

    if save == true then

        cash.Value = datastore:GetAsync("Gold"..join.Name)
    end
end)

game.Players.PlayerRemoving:connect(function(leave)
    if save == true then

        datastore:SetAsync("Gold"..leave.Name, Gold.Value)
    end
end)

Level up script:

local level = Instance.new("IntValue")
level.Name = "Level"
level.Value = 1
function onxpChanged(player, XP, level)
        if XP.Value>=level.Value * 50 then
            XP.Value = XP.Value - level.Value * 50
            level.Value = level.Value + 1
            local healthincrease = 50
       end
    end

    function onLevelUp(player, XP, level)
        if player.Character~=nil then
            for i = 1,5 do
                local fireworks = Instance.new("Part")
                fireworks.Shape = 0
                fireworks.formFactor = "Symmetric"
                fireworks.Size = Vector3.new(1,1,1)
                fireworks.BrickColor = BrickColor.Random()
                fireworks.CFrame = player.Character.Head.CFrame + Vector3.new(0,2,0)
                fireworks.Parent = game.Workspace
                game:GetService("Debris"):AddItem(fireworks, 2)
                fireworks.Velocity = Vector3.new(math.random(-30,30),math.random(-30,30),math.random(-30,30))
            end
        end
        local m = Instance.new("Hint")
        m.Parent = game.Workspace
        m.Text = player.Name .. "Leveled up"
        wait(3)
        m.Parent = nil
    end

    function onPlayerRespawned(player)
        wait(5)
        player.Character.Humanoid.Health = player.leaderstats.Level * 100
        player.Character.Humanoid.MaxHealth = player.leaderstats.Level * 100

    end

    function onPlayerEntered(newPlayer)
        local stats = Instance.new("IntValue")
        stats.Name = "leaderstats"

        local xp = Instance.new("IntValue")
        xp.Name = "XP"
        xp.Value = 0

        local level = Instance.new("IntValue")
        level.Name = "Lvl"
        level.Value = 1

        local c = Instance.new("IntValue")
        c.Name = "Gold"
        c.Value = 0

        xp.Parent = stats
        level.Parent = stats
        c.Parent = stats

        stats.Parent = newPlayer

        xp.Changed:connect(function() onXPChanged(newPlayer, xp, level) end)
        level.Changed:connect(function() onLevelUp(newPlayer, xp, level) end)

        newPlayer.Changed:connect(function (property)
            if (property == "Character") then
                onPlayerRespawned(newPlayer)
            end
        end)
    end

    game.Players.ChildAdded:connect(onPlayerEntered)

XP script:

XP = script.Parent.Parent.Parent.Parent.Parent.leaderstats.XP
level = script.Parent.Parent.Parent.Parent.Parent.leaderstats.Lvl

while true do
script.Parent.Text = "XP: " .. XP.Value .. " / " .. level.Value * 50 
wait(0.1)
end

XP fill bar script:

XP = script.Parent.Parent.Parent.Parent.Parent.leaderstats.XP
level = script.Parent.Parent.Parent.Parent.Parent.leaderstats.lvl

while true do
wait()
local pie = ( XP.Value / (level.Value * 50)) 
script.Parent.Size = UDim2.new( pie , 0 , 0, 20)
end

Enemy Gold and XP on death script:

local Humanoid = script.Parent.Humanoid
function PwntX_X() 
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.Gold.Value = Leaderstats.Gold.Value + 1 
wait(0.1)
script:remove()
            end 
        end 
    end 
end 
Humanoid.Died:connect(PwntX_X) 




local Humanoid = script.Parent.Humanoid 
function PwntX_X() 
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.XP.Value = Leaderstats.XP.Value + 2 
wait(0.1) 
script:remove()
            end 
        end 
    end 
end 
Humanoid.Died:connect(PwntX_X) 

Current Gold GUI script

while true do
script.Parent.Text = "Gold: " .. math.floor(script.Parent.Parent.Parent.Parent.Parent.leaderstats.Gold.Value)
wait(0)
end

Current Level GUI script:

while true do
script.Parent.Text = "Level: " .. math.floor(script.Parent.Parent.Parent.Parent.Parent.leaderstats.Lvl.Value)
wait(0)
end

These are all the related scripts, please tell me my fault. Thanks for reading.

0
You may need to try to put everything in one script. minetrackmania 186 — 8y
0
Why don't you cut out some of the scripts and organize everything a lot better. LateralLace 297 — 8y

Answer this question