I have made a leaderboard script that has levels and xp, I wanted to add money but now my levels dont work as everyones level is supposed to be level 1 but once I added money to the leaderboard the level is 0 for everyone.. I also tried to Store the Data.. But that does not want to work as "cry" is a nil value on line 54, please help me with this! I really want this to work and have been trying to get it working for 2 days now!
I just want to make a simple leaderboard script that has Levels, XP, Money and can save them to the server..
local DataStore = game:GetService("DataStoreService")
local lvl = DataStore:GetDataStore("LevelSaveSystem1")
local levels, exp, bills = {}, {}, {}
game.Players.PlayerAdded:connect(function(player)
local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"
local Level = Instance.new("IntValue",leaderstats)
Level.Name = "Level"
Level.Value = lvl:GetAsync(player.UserId) or 1
levels[player] = Level
Level.Changed:connect(function()
lvl:SetAsync(player.UserId, Level.Value)
end)
if (Level.Value > 100) then -- MaxLevel
Level.Value = 100
end
local DataStore = game:GetService("DataStoreService")
local xp = DataStore:GetDataStore("LevelSaveSystem")
local XP = Instance.new("IntValue",leaderstats)
XP.Name = "XP"
XP.Value = xp:GetAsync(player.UserId) or 0
exp[player] = XP
XP.Changed:connect(function()XPChange(player,XP,Level) end)
xp:SetAsync(player.UserId, XP.Value)
local DataStore = game:GetService("DataStoreService")
local cry = DataStore:GetDataStore("MoneySaveSystem")
local Coins = Instance.new("IntValue",leaderstats)
Coins.Name = "Coins" -- Currency name here
Coins.Value = cry:GetAsync(player.UserId) or 0 -- Starting money
bills[player] = Coins
cry:SetAsync(player.UserId, Coins.Value)
end)
function XPChange(player,XP,Level)
if XP.Value >= Level.Value*50 then -- Takes 50 XP to get to Level 2 then 100 XP to get to Level 3 etc... also If you level up then...
XP.Value = 0
Level.Value = Level.Value+1
end
end
game.Players.PlayerRemoving:connect(function(player)
lvl:SetAsync(player.UserId, levels[player].Value)
lvl:SetAsync(player.UserId, exp[player].Value)
DataStore:GetDataStore("LevelSaveSystem1"):SetAsync(player.UserId, exp[player].Value)
cry:SetAsync(player.UserId, bills[player].Value)
DataStore:GetDataStore("MoneySaveSystem"):SetAsync(player.UserId, bills[player].Value)
end)

3 comments
Cry was declared as a local variable of Line 32, it cannot be referenced outside of it’s scope
I think we can all tell this Script isn’t yours either
It is not all mine but most parts of it are.. I have been working on this for 2 days now coming onto 3.