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

For some reason SetAsync doesnt work but everything before it does. Can somebody help me?

ive got a script that creates leaderstats, loads leaderstats and saves leaderstats but its the saving part that doesnt work. For some unkown reason everything in this script works up to the pcall and everything after that just decides to not work and i have no idea why. This has been plagueing me for a whole 2 days and at least 20 hours of those 2 days ive spent trying to fix it so i will take any help

game.Players.PlayerRemoving:Connect(function(player)
	print("player removing working")
	local money = player.leaderstats.money.Value
	local strength = player.leaderstats.strength.Value
	local newplayer = player.leaderstats.newplayer.Value
	print ("Variable assign working")
	local dataDict = {
		moneydata = money,
		strengthdata = strength,
		newplayerdata = newplayer,
	}
	local success, errormessage = pcall(function()
		gameDataStore:SetAsync(player.UserId,dataDict)
	end)
	if success then
		print("data saved")
	else
		print("data failed")
		warn(errormessage)
	end		
	print("why is this not working")
	print(dataDict["moneydata"])
	print("finished")
end)

4 comments

0

How are you sure that it's not your loading script that's flawed? Can you post that too?

0

Ive got a similar setup with the loading and it prints to console the success message

0

show the loading anyway

0

you know we can't help you if you post inadequate information right

1 answer

Use this:

--Converts to a string table
game.HttpService:JSONEncode(Table)

--Converts back into a table
game.HttpService:JSONDecode(Table)

Why? In my opinion, putting a table directly into a datastore is funky, but it may work with some tweaking.

10 comments

0

Dictionarys work too, its also a really good way to print a dictionary.

0

should i convert the table into a string before storing it and convert back into a string before pulling a value?

0

yes

0

However, putting an object through will turn into nil

0

this seems like it should work but for some reason the script is still halted before it stores the data

0

where does it stop?

0

it stops at the pcall and i know this because nothing it printed to console

0

mabye try: spawn(function() --Saving pcall end). Just to see what happens

0

spawn(function() end), if it was unclear

0

it didnt do anything and i appreciate your help with this

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