Hi, I am just working on a data store system that saves Gems and Coins.
But I does not save any data, and I always get the message (after pcall) “data store not saved” (that I wrote).
I do not know why this data store doesnt work, and I would love to get help!
It also thinks that the player never has joined, indicating that the data is not being saved.
Script:
DataStoreService = game:GetService("DataStoreService")
CurrencyData = DataStoreService:GetDataStore("CurrencyData")
game.Players.PlayerAdded:Connect(function(Player)
local PlayerData;
local CurrencyDataFolder = Instance.new("Folder")
CurrencyDataFolder.Name = "CurrencyDataFolder"
CurrencyDataFolder.Parent = Player
local GemsFolder = Instance.new("IntValue")
GemsFolder.Name = "Gems"
GemsFolder.Parent = CurrencyDataFolder
local CoinsFolder = Instance.new("IntValue")
CoinsFolder.Name = "Coins"
CoinsFolder.Parent = CurrencyDataFolder
local DataFetchSuccess, ErrorMessage = pcall(function()
PlayerData = CurrencyData:GetAsync(tostring(Player.UserId))
end)
if DataFetchSuccess then
print("data fetch success")
if PlayerData ~= nil then
Player.CurrencyDataFolder.Coins.Value = PlayerData[1]
Player.CurrencyDataFolder.Gems.Value = PlayerData[2]
else
print("not joined before")
Player.CurrencyDataFolder.Coins.Value = 2000
Player.CurrencyDataFolder.Gems.Value = 10
end
else
Player:Kick("Data failed to load, pleaser rejoin.") --teleporter dem til et annet spill i 2 sec også tilbake uten at de merker det. (Men programer senere)
end
end)
--player leaving
game.Players.PlayerRemoving:Connect(function(Player)
print("player left " .. Player.Name)
local PlayerData = {Player.CurrencyDataFolder.Coins.Value, Player.CurrencyDataFolder.Gems.Value}
print(Player.CurrencyDataFolder.Coins.Value)
local DataSaveSuccess, DataSaveError = pcall(function()
CurrencyData:SetAsync(tostring(Player.UserId, PlayerData))
print("saved the data")
end)
if not DataSaveSuccess then
print("no data save success") --always prints this
local DataSaveAttempts = 0
while DataSaveAttempts < 6 do
wait(60)
local RetrySaveSuccess, RetrySaveError = pcall(function()
CurrencyData:SetAsync(tostring(Player.UserId), PlayerData)
end)
if RetrySaveSuccess then
break
end
end
DataSaveAttempts = DataSaveAttempts + 1
end
print("done with the saving data")
end)