local dataStoreService = game:GetService("DataStoreService")
local players = game:GetService("Players")
local mainStore = dataStoreService:GetDataStore("Main")
players.PlayerAdded:Connect(function(player)
local ld = Instance.new("Folder", player)
ld.Name = "leaderstats"
local hld = Instance.new("Folder", player)
hld.Name = "HideLeaderstats"
local coins = Instance.new("IntValue", ld)
coins.Name = "Coins"
coins.Value = 0
local timeCoins = Instance.new("IntValue", hld)
timeCoins.Name = "TimeCoins"
timeCoins.Value = 0
local clickPower = Instance.new("IntValue", hld)
clickPower.Name = "ClickPower"
clickPower.Value = 1
local success, data = pcall(function()
return mainStore:GetAsync(player.UserId)
end)
if success then
coins.Value = data or 0
timeCoins.Value = data or 0
clickPower.Value = data or 1
else
print("data failed to load")
end
end)
players.PlayerRemoving:Connect(function(player)
local ld = player:WaitForChild("leaderstats")
local hld = player:WaitForChild("HideLeaderstats")
local coins = ld:WaitForChild("Coins")
local timeCoins = hld:WaitForChild("TimeCoins")
local clickPower = hld:WaitForChild("ClickPower")
local success, err = pcall(function()
return mainStore:SetAsync(player.UserId, coins.Value, timeCoins.Value, clickPower.Value)
end)
if not success then
print(err)
end
end)
When I leave out of the game, it says this:
Unable to cast to Array
It’s this line right here:
if not success then
print(err)
end
Is that why my data is not being saved and it’s writing this problem?