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

Using DataStore

I'm trying to figure out how I can save and update a "key" in the datastore with a table. I've never used DataStore before so I'm trying to figure out how it works.

I have{plr.Name, servername, password, public};and I want to save that to the next position in the serverList table.

serverData = game:GetService("DataStoreService"):GetDataStore("ds")
serverList = {}
if serverData:GetAsync("Servers") then
	serverData:SetAsync("servers", serverData:GetAsync("servers"))
else
	serverData:SetAsync("servers", serverList)
end


function Workspace.createServer.OnServerInvoke(plr, servername, password, password2)
	print(plr.userId)
	local public = false
	if password2 ~= "" then
		print(plr.Name.." wishes to create a server called "..servername.." with the password "..password)
		public = false
	else
		print(plr.Name.." wishes to create a server called "..servername.." without a password")
		public = true
	end
	table.insert(serverList, #serverList+1, {plr.Name, servername, password, public})
	serverData:UpdateAsync("servers", function(serverList) return serverList[#serverList] end)
end

1 answer

✓ Accepted answer
serverList[#serverList+1] = {plr.Name, servername, password, public}

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