My script has been working for quite a while, but recently I've had to flip variables around and junk to make the script is cleaner. After I did, I got a strange error: Workspace.Leaderboard Script:28: attempt to index global 'Cash' (a nil value) what could this mean? My appreciation in advanced for any help you can give.
game.Players.PlayerAdded:connect(function(padd)
--Variables
local PlayerBag=Instance.new("Configuration",padd)
local LeaderStats=Instance.new("Model",padd)
local Cash=Instance.new("IntValue",LeaderStats)
local item1=Instance.new("BoolValue",PlayerBag)
--Names
PlayerBag.Name="PlayerBag"
LeaderStats.Name="leaderstats"
Cash.Name="Cash"
item1.Name="Item1"
--DataReady
padd:WaitForDataReady()
Cash.Value = padd:LoadNumber("Cash")
item1.Value = padd:LoadNumber("Item1")
end)
--DataSave
game.Players.PlayerRemoving:connect(function(premove)
local leaderstats=premove:FindFirstChild("leaderstats")
local playerbag=premove:FindFirstChild("PlayerBag")
if leaderstats then
local cash=leaderstats:FindFirstChild("Cash")
if cash then
premove:SaveNumber("Cash",Cash.Value)
end
end
if playerbag then
local i1=PlayerBag:FindFirstChild("item1")
if i1 then
premove:SaveBoolean("Item1",i1.Value)
end
end
end)
--CashGeneration
while wait(1) do
for _,Player in pairs(game.Players:GetPlayers()) do
if Player:FindFirstChild("leaderstats") then
Player.leaderstats.Cash.Value=Player.leaderstats.Cash.Value +1
end
end
end

1 comment
Use Datastore not Data Persistence