I’ve used this system to save data in a few of my games and it’s been fine, but today when I’m testing the game it keeps giving me the error “Unable to cast value to Object”
local Players = game:GetService("Players")
local dss = game:GetService("DataStoreService")
local DataStoreGold = dss:GetOrderedDataStore("Gold")
local function leaderboardSetup(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local gold = Instance.new("IntValue")
gold.Name = "Gold"
gold.Parent = player.leaderstats
gold.Value = DataStoreGold:GetAsync(player.UserId, player.leaderstats.Gold.Value) or 0
end
local function playerleft(player)
DataStoreGold:SetAsync(player.UserId, player.leaderstats.Gold.Value)
end
Players.PlayerAdded:Connect(leaderboardSetup)
Players.PlayerRemoving:Connect(playerleft)
I don’t know why this is happening and would appreciate it if someone could help