Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

SetAsync not actually saving when player leaves game?

I am trying to make save and load, but I ran into one problem: SetAsync does not save, unless I set it manually. I have tried datastore plugins such as DataStoreX, but none have worked. Code:

local DataStoreService = game:GetService("DataStoreService")
local dataStore = DataStoreService:GetDataStore("DAT")

game.Players.PlayerAdded:Connect(function(player)
	local coins = Instance.new("IntValue")
	coins.Name = "coins"
	coins.Parent = player
	
	local playerUserId = "Player_"..player.UserId
	local success, err = pcall(function()
		coins.Value = dataStore:GetAsync(playerUserId)
	end)

	if success then
		print("Load success!")
	else
		warn(err)
	end
	print(player.coins.Value)
end)

game.Players.PlayerRemoving:Connect(function(player)
	local success, err = pcall(function()
		print(player.coins.Value)
		local playerUserId = "Player_"..player.UserId
		dataStore:SetAsync(playerUserId, player.coins.Value)
	end)
	
	if success then
		print("Save success!")
	else
		warn(err)
	end
end)

game:BindToClose(function()
	wait(5)
end)

NOTE #1: I TRIED SAVING IN BOTH BINDTOCLOSE AND PLAYERREMOVING, BUT IT STILL DIDN'T SAVE. NOTE #2: I'M RUNNING INSIDE ROBLOX STUDIO

5 comments

0

Put stuff in the BindToClose that saves data for everyone in the server, should work then.

0

^ yeah, you should save during PlayerRemoving and BindToClose

0

I tried that, except i get this error: DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = Player_1217140517

0

hello?

0

that's fine as long as u don't spam save every second.

1 answer

I tried it, and it didn't happen that it won't save. Try to restart the studio or restart the computer. Image: https://gyazo.com/4541af38180329af133b8f6e121eacbb

2 comments

0

That didn't work. I have Datastore Editor, but can only change data with that. I also restarted my Macbook and Studio a few hours ago.

0

btw heres what i mean: I have a button. I click the button 5 times. My number that is meant to be saved is 5. I leave the game. In the script, inside my PlayerRemoving, it is printing the value of my coins. It prints 0, instead of 5. I play it again. It also prints 0 to the console.

This discussion is preserved as it was. New answers, comments, and votes are closed.