So I made this data store script and I’m not sure whats wrong with it, it prints the success messages but the data still doesn’t load, I have API services on as wellas https. Any suggestions or solutions?
local DataStoreService = game:GetService("DataStoreService")
local CashStore = DataStoreService:GetDataStore("Cash")
local queue = 0
game.Players.PlayerAdded:Connect(function(Player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = Player
local Cash = Instance.new("IntValue")
Cash.Name = "Cash"
Cash.Value = 0
Cash.Parent = leaderstats
local data
local Success, Error = pcall(function()
data = CashStore:GetAsync(Player.UserId.."-cash")
end)
if Success then
Cash.Value = data
print("Data Found!")
else
warn(Error)
end
end)
game.Players.PlayerRemoving:Connect(function(Player)
queue += 1
local Sucess, Error = pcall(function()
CashStore:SetAsync(Player.UserId.."-Cash", Player.leaderstats.Cash.Value)
end)
if Sucess then
print("Data Saved!")
queue -= 1
else
warn(Error)
end
end)
game:BindToClose(function()
repeat wait() until queue == 0
end)