Ad
Log in to vote
0

Using DataStore

Asked by 7 years ago

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

Log in to vote
6
Answered by
Azarth 3118 Moderation Voter Community Moderator
7 years ago
serverList[#serverList+1] = {plr.Name, servername, password, public}
Ad

Answer this question