Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

most efficient way to put data into data stores?

Asked by 9 years ago

In the game I'm working on, people receive gear and hats. and I hear that the way to save this is with data stores. I have a few ideas on how I could save the items, but I was wondering what the most efficient way is. Thanks in advance!

2 answers

Log in to vote
1
Answered by
4Bros 550 Moderation Voter
9 years ago

Well, there are many ways to go about this to make it the most efficient but what you could do is save each player's userid as the key, and save a table of the names of all their gear to the key. You could keep the gear in the serverstorage and sift through all the strings in the table and use findfirstchild to get the gear.

local datastore = game:GetService'DataStoreService':GetDataStore("gears")
local serverstorage = game:GetService'ServerStorage'


game:GetService'Players'.PlayerAdded:connect(function(p)
local key = p.UserId
    p.CharacterAdded:connect(function(c)
        local data = datastore:GetAsync(key) 
        if data and data ~= nil then
            for i,v in pairs(data) do
                local found = serverstorage:FindFirstChild(v:lower(),true)  
                if found then
                    found:Clone().Parent = p:WaitForChild'Backpack'
                end
            end
        else
            datastore:SetAsync(key,{})
        end
    end)
end)

that's as far as i'll go to show you how to do it

0
Thanks! That's really useful and actually a lot simpler than my original idea nightshade7382 20 — 9y
Ad
Log in to vote
-1
Answered by 9 years ago

I think DataStores. Try the ROBLOX wiki!

Answer this question