0
votes

I have been working on a Roblox game for about three weeks, and have created something that I am proud of, but I have one pretty significant error that I can't seem to work around. I want to make the game something that I can add to in the future, so I made a program to reward players with gold and exp points for killing NPC's. I also made a GUI bar to show the player their progress towards the next level. The problem I have is the gold will show up, but the xp will not. I have been banging my head against a brick wall as I have tried over seventy fixes, and the xp still will not show up on the bar and the player can't level.

My xp bar program looks like this:

--Player related variables--
local player = game.Players.LocalPlayer
local level = player:WaitForChild("Level")
local current = level:WaitForChild("Current")
local max = level:WaitForChild("Max")

--UI related variables--
local gui = script.Parent
local exterior = gui:WaitForChild("Exterior")
local label = exterior:WaitForChild("Label")
local exp = exterior:WaitForChild("Exp")
local bar = exterior:WaitForChild("Bar")

--Change stats upon join--
label.Text = "Level "..level.Value
exp.Text = current.Value.."/"..max.Value.." Exp"
bar.Size = UDim2.new(current.Value/max.Value, 0, 1, 0)

level.Changed:Connect(function(val, level)
    label.Text = "Level "..level.Value
    exp.Text = current.Value.."/"..max.Value.." Exp"
    bar.Size = UDim2.new(current.Value/max.Value, 0, 1, 0)
    wait(1)
end)

current.Changed:Connect(function(val)
    exp.Text = current.Value.."/"..max.Value.." Exp"
    bar.Size = UDim2.new(current.Value/max.Value, 0, 1, 0)
    wait(1)
end)

and my reward program looks like this:

        
local Humanoid = script.Parent.Humanoid
local Experience = 10
function Dead()
    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.Cash.Value = leaderstats.Cash.Value +50
                
                workspace.ServerScriptService.leaderstats.Current:Connect(function(Experience)
                    if leaderstats.Current.Value ~= nil then
                        leaderstats.Current.Value = leaderstats.Current.Value + Experience
                        else leaderstats.Current.Value = 10
                        end
                end)
                
                wait(0.1)
                script:Remove()
                
            end
        end
    end
end

Humanoid.Died:Connect(Dead)

I also have a leaderstats code that looks like this:


        
local DataStore = game:GetService("DataStoreService"):GetDataStore("butthole")



game.Players.PlayerAdded:Connect(function(player)
    
    
    local folder = Instance.new("Folder")
    folder.Name = "leaderstats"
    folder.Parent = player
    
    local cash = Instance.new("IntValue")
    cash.Name = "Cash"
    cash.Value = 900
    cash.Parent = folder
--start
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
        level.Value = level.Value + 1
        exp.Value = 0
        maxExp.Value = maxExp.Value * 2.5
        
        end

Something isn't talking to something else correctly, but I can't figure out where that might be. I'm not a pro developer, I'm just a guy trying to make a game.