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

Stuck at SetAsync Loading works saving does not. Help please?

Data = { -- Multiple StringValues -- }


if Data ~= nil and Data[1] and Data[1] ~= nil then

local DataStoreService = game:GetService("DataStoreService")

print("newsave1")

DataStoreService:GetDataStore("Datastore"):SetAsync(player.UserId, Data)

print("newsave2")

end

It prints newsave1 and stays at SetAsync not printing newsave2 i have no idea whats going on.

Please let me know if you know anything.

2 answers

I am pretty sure the error is on line 4 so I will attempt to make another script that could probably help you understand how to use datastores and SetAsyncs, script in workspace, regular script!

game.Players.PlayerAdded:connect(function(p)
	local count = 1
	local plrKey = "Id-"..p.UserId
	locla ds = game:GetService("DataStoreService"):GetDataStore("Data") -- get data storage
	data = {} or nil -- use table.Insert for this stuff
	local savedValues = DataStore:GetAsync(key)
	for _, SaveData in pairs(data) do -- loops created
		local NewValue = Instance.new("StringValue", workspace) -- change to whatever suits you, remember to edit stuff then
		NewValue.Value = SaveData.Name
		if savedValues then
			NewValue.Value = savedValues[count]
			count = count + 1
		else
			local valuesToSave = {NewValue.Value}
		end
	end
end


game.Players.PlayerRemoving:connect(function(p) -- when players are about to go :O
	
	local key = "Id-"..p.userId
	
	--Save key: {Data}
	local valuesToSave = {data}
	DataStore:SetAsync(key, valuesToSave)
	
end)

This is a rough untested example of how I would do things to save strings and use SetAsync ^, Hope this helps

Theres no problem with line 04 because line 08 did print but line 12 did not print.

Could it be a problem when my script gets the children of a model and inserts the name and value into the table (data) whenever the player leaves?

1 comment

0

Found the solution getting the children took too long so when it was done the player was already gone and it couldnt take the userid from it to save.

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