I have tried EVERYTHING, EVERYTHING. And I cannot get DataStores to work completely for my game. I’ve tried numerous tutorials, nothing, AI, nothing, help from other scripters, nothing.
Here’s the script, and when I mean it doesn’t work completely I mean only “Coins” and “Gems” save, nothing else does. Exp, Level and QuestNum don’t save and I’ve looked through a ton of scripts for things that could be affecting it but nothing has worked. Please help, I’m reaching the deadline for releasing my game and I can’t without DataStore.
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("Data")
local function SaveData(Player)
local TableToSave = {
Player.leaderstats.Coins.Value;
Player.leaderstats.Gems.Value;
Player.leaderstats.Level.Value;
Player.leaderstats.Exp.Value;
Player.QuestNum.Value;
}
local success, errorMessage = pcall(DataStore.SetAsync, DataStore, Player.UserId, TableToSave)
if success then
print("Player data saved for "..Player.Name..".")
else
print("Player data not saved for "..Player.Name.."!")
end
end
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Wait()
local leaderstats = Player.leaderstats
local Data = nil
local success, errorMessage = pcall(function()
Data = DataStore:GetAsync(Player.UserId)
end)
if success and Data then
leaderstats.Coins.Value = Data[1]
leaderstats.Gems.Value = Data[2]
leaderstats.Level.Value = Data[3]
leaderstats.Exp.Value = Data[4]
Player.QuestNum.Value = Data[5]
else
print("No player data found for "..Player.Name.."!")
warn(errorMessage)
end
end)
game.Players.PlayerRemoving:Connect(function(Player)
SaveData(Player)
end)
game:BindToClose(function()
for _, Player in ipairs(game.Players:GetPlayers()) do
task.spawn(SaveData, Player)
end
end)