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

Completely confused with DataStores?

Months after I've been introduced to data stores, I still don't understand how to use them. I tried this script in Workspace in studio, and the output just tells me that "An error occurred." In the test server, it tells me absolutely nothing. I have no idea what I'm doing wrong here.

datastore = game:GetService("DataStoreService"):GetDataStore("PlayerData by UserID")
http = game:GetService("HttpService")
http.HttpEnabled = true

Default = {
	["Level"] = 1,
	["Gold"] = 100,
	["AdminStatus"] = "User"
}

JCodedDefault = http:JSONEncode(Default)
game.Players.PlayerAdded:connect(
	
function(player)
	print("Attempting to access "..player.Name.."'s data...")
	wait(3)
	
	if not datastore:GetAsync(player.userId) then
		print(player.Name.."'s data has not been found. Attempting to write default data...")
		wait(3)
		
		datastore:SetAsync(player.userId, JCodedDefault)
		
		if datastore:GetAsync(player.userId) then
			print("Successful.")
		else
			print("Failed.")
		end
		
	else 
		print("Successful.")
	end
end

)

2 comments

0

I know it's SetAsync and not PostAsync. I was thinking about HttpService for a moment.

0

You can make the PostAsync into SetAsync by using the Edit button, so alot of DataStore learners wont be confused

1 answer

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