It’s highly recommended that you encase your DataStore functions inside pcalls, so that you properly know what Outputs back & you can see the results it returned back
local datastore = game:GetService("DataStoreService"):GetDataStore("data")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Parent = player
leaderstats.Name = "leaderstats"
local Gold = Instance.new("NumberValue")
Gold.Parent = leaderstats
Gold.Name = "Gold"
local Rebirths = Instance.new("NumberValue")
Rebirths.Parent = leaderstats
Rebirths.Name = "Rebirths"
local debounce = Instance.new("BoolValue")
debounce.Value = false
debounce.Name = "Debounce"
debounce.Parent = player
local key = "user-" .. player.UserId
local storeditems
local success, whoops = pcall(function()
storeditems = datastore:GetAsync(key)
end)
if success and storeditems then
print("Data loaded successfully!")
Gold.Value = storeditems[1]
Rebirths.Value = storeditems[2]
else
warn(whoops)
Gold.Value = 0
Rebirths.Value = 0
end
end)
game.Players.PlayerRemoving:connect(function(player)
local items = {player.leaderstats.Gold.Value, player.leaderstats.Rebirths.Value}
local key = "user-" .. player.UserId
local success, whoops = pcall(function()
datastore:SetAsync(key, items)
end)
if success then
print("Data saved successfully!")
else
warn(whoops)
end
end)
Also double check to make sure that API Services in your Game Settings are Enabled