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

Global PlrLeaderstatsData 'Unknown Global'? (Datastore)

Asked by 6 years ago
local DS = game:GetService("DataStoreService")
local Coins = DS:GetDataStore("Coins")
local PlrCoinsData = {}

game.Players.PlayerAdded:Connect(function(plr)
    local Bool, PlrData = pcall(Coins.GetAsync, Coins, plr.UserId.."_Coins")
    local Bool2, PlrData = pcall(Coins.GetAsync, Coins, plr.UserId.."_leaderstats")
    local leaderstats = Instance.new("IntValue")
    PlrleaderstatsData[plr.UserId] = leaderstats
        leaderstats.Parent = plr
    local Coins = Instance.new("IntValue")
    PlrCoinsData[plr.UserId] = Coins
    Coins.Name = "Coins"
    Coins.Value = Bool and PlrData or 0
    Coins.Parent = plr.leaderstats

end)

game.Players.PlayerRemoving:Connect(function(plr)
    pcall(Coins.SetAsync, PlrCoinsData[plr.UserId].Value, plr.UserId.."_Coins")
    pcall(Coins.GetAsync, PlrleaderstatsData, plr.UserId.."_leaderstats")
end)

game:BindOnClose(function()
    for _, plr in next, game.Players:GetPlayers() do
      spawn(function()
              pcall(Coins.SetAsync, PlrCoinsData[plr.UserId].Value, plr.UserId.."_Coins")
              pcall(Coins.GetAsync, PlrLeaderstatsData[plr.UserId].Value, plr.UserId.."_leaderstats")
      end)
    end
end)

--PlrLeaderstats Data is Unknown Global, help!

2
I think you just forgot to initialize PlrLeaderstatsData GoldAngelInDisguise 297 — 6y

Answer this question