Hi, I am working on a data storage system for my game and am confused about why it is not saving any of the player’s data, I have API turned on and everything should be good, but it still isn’t saving. Any help would be awesome thank you!!!
local dataStoreServivce = game:GetService("DataStoreService")
local dataStore = dataStoreServivce:GetDataStore("Main1")
local Click = game.ReplicatedStorage.Click
local rebirthEvent = game.ReplicatedStorage.rebirthEvent
local multiplier = 25
local rebirthEvent2 = game.ReplicatedStorage.rebirthEvent2
local rebirthEvent3 = game.ReplicatedStorage.rebirthEvent3
local rebirthEvent4 = game.ReplicatedStorage.rebirthEvent4
local function saveData(player)
local tableToSave = {
player.leaderstats.Clicks.Value,
player.leaderstats.Rebirths.Value,
player.leaderstats.Coins.Value
}
local success, err = pcall(function()
dataStore:GetAsync(player.UserId, tableToSave)
end)
if success then
print("Data Saved!")
else
print("Data Was Not Saved!")
warn(err)
end
end
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder", plr)
leaderstats.Name = "leaderstats"
local Clicks = Instance.new("IntValue")
Clicks.Name = "Clicks"
Clicks.Value = 0
Clicks.Parent = leaderstats
local Coins = Instance.new("IntValue")
Coins.Name = "Coins"
Coins.Value = 0
Coins.Parent = leaderstats
local Rebirths = Instance.new("IntValue")
Rebirths.Name = "Rebirths"
Rebirths.Value = 0
Rebirths.Parent = leaderstats
local data
local success, err = pcall(function()
data = dataStore:GetAsync(plr.UserId)
end)
if success and data then
Clicks.Value = data[1]
Rebirths.Value = data[2]
Coins.Value = data[3]
print("Data Loaded!")
else
print("Player Has No Data!")
end
end)
game.Players.PlayerRemoving:Connect(function(player)
saveData(player)
end)
game:BindToClose(function()
for _, player in pairs(game.Players:GetChildren()) do
saveData(player)
end
end)