For some reason, my coins in the game only save whenever they are increased. When they are decreased and I leave the game it loads back at what the coins used to be before they were decreased. I tried a solution to fix this which was save the coins whenever they changed but it didn't work. I also tried playing in Roblox studio and Roblox itself but it didn't work.
Also sometimes the floors dont save.
Server Script
local DataStoreService = game:GetService("DataStoreService")
local GameDataStore = DataStoreService:GetDataStore("GameDataStore")
local Players = game:GetService("Players")
local function leaderboardSetup (player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Coins = Instance.new("IntValue")
Coins.Name = "Coins"
Coins.Value = 0
Coins.Parent = leaderstats
local Floors = Instance.new("IntValue")
Floors.Name = "Floors"
Floors.Value = 0
Floors.Parent = leaderstats
local Items = Instance.new("Folder")
Items.Name = "Items"
Items.Parent = player
local SC = Instance.new("IntValue")
SC.Name = "SC"
SC.Parent = Items
SC.Value = 0
local TimeT = Instance.new("IntValue")
TimeT.Name = "TimeT"
TimeT.Parent = Items
TimeT.Value = 0
local data
local data2
local success, errormessage = pcall(function()
data = GameDataStore:GetAsync(player.UserId.."Floors")
data2 = GameDataStore:GetAsync(player.UserId.."Coins")
end)
if success then
Floors.Value = data
Coins.Value = data2
print("YAY UR DATA LOADED UWU")
else
print("NO NO NO DATA DINDT LOAD THIS ISNT GOOD SADYWFDYUWADYAGDWYUIDuwu...")
warn(errormessage)
end
end
Players.PlayerAdded:Connect(leaderboardSetup)
Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
GameDataStore:SetAsync(player.UserId.."Floors",player.leaderstats.Floors.Value)
GameDataStore:SetAsync(player.UserId.."Coins",player.leaderstats.Coins.Value)
end)
if success then
print("Data saved! OMG SO MUCH UWUW NOISES CONGRATS")
else
print("OH NO DATA NO SAVED SAD WUYD*AWDGUIWDOAYWDIUYAWD")
warn(errormessage)
end
end)

1 comment
This didn't fix my problem, I did what you said except for UpdateAsync but it only saved my coins when it went higher still.