So i have here a datastore script for my currency ‘Tix’ and it wont save . Can you please help?
local datastoreservice = game:GetService("DataStoreService")
local datastore = datastoreservice:GetDataStore("DATA33333")
game.Players.PlayerAdded:Connect(function(player)
local tokens = Instance.new("IntValue")
tokens.Name = "Tix"
tokens.Value = 0
tokens.Parent = player
local data
local success,errorMsg = pcall(function()
data = datastore:GetAsync(player.UserId)
end)
if data ~= nil then
if data.Tokens then
tokens.Value = data.Tokens
end
end
end)
game:BindToClose(function()
-- will run when the server is about to shutdown
for i, player in pairs(game.Players:GetPlayers()) do
local data = {}
data.Tokens = player.Tix.Value
local success,errorMsg = pcall(function()
datastore:SetAsync(player.UserId,data)
end)
if success then
print("Success")
end
if errorMsg then
print("Error found while trying to save data (are roblox datastore servers down?)"..errorMsg)
end
end
end)
local trapDebounce = false
game.Players.PlayerRemoving:Connect(function(player)
local data = {}
data.Tokens = player.Tix.Value
local success,errorMsg = pcall(function()
datastore:SetAsync(player.UserId,data)
end)
if success then
print("Success")
end
if errorMsg then
print("Error found while trying to save data (are roblox datastore servers down?)"..errorMsg)
end
end)
local datastoreservice = game:GetService("DataStoreService")
local datastore = datastoreservice:GetDataStore("DATA33333")
game.Players.PlayerAdded:Connect(function(player)
tokens = Instance.new("IntValue")
tokens.Name = "Tix"
tokens.Value = 0
tokens.Parent = player
local success, data= pcall(function()
datastore:GetAsync(player.UserId .. "TIX")
end)
if data ~= nil then
if data then
tokens.Value = data
end
end
end)
local trapDebounce = false
game.Players.PlayerRemoving:Connect(function(player)
local success,errorMsg = pcall(function()
datastore:SetAsync(player.UserId .. "TIX", tokens.Value)
end)
if success then
print("Success")
end
if errorMsg then
print("Error found while trying to save data (are roblox datastore servers down?)"..errorMsg)
end
end)
That isn’t twice, y’know, it’s Server not Client shutting down. And the server might struggle with it. I have the same building scheme as this guy does, but it works perfectly fine for me.