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

Can I save Datastore-info in variables or something?

Asked by 2 years ago

Hi, I'm making a game where you attack other players' bases. Kind of like in Clash Of Clans. The problem is that my script for loading the bases is somehow too slow. Here is the "main part" of the script

local dsb = game:GetService("DataStoreService"):GetDataStore("Buildingsalpha")

local folder = Instance.new("Folder")
folder.Parent = workspace
folder.Name = "buildings"

for i = 1, #workspace.BuildingRaster:GetChildren() do
    local raster = workspace.BuildingRaster

    local buildings = dsb:GetAsync(players[player])

    if buildings[i] ~= "LEER" then
        local gebaude = game.Lighting[buildings[i]]:Clone()
        gebaude.Parent = workspace.buildings
        gebaude:MoveTo(raster[i].Position)
    end
end

"players [player]" is the id of the random base player. It is probably running slowly because of the datastore instead of everything running immediately. Is it possible to save datastore information in variables or something so that the script does not always have to query the datastore? The datastore info is a table, for information only. I look forward to answering.

0
I wanted to say that I actually speak German and that's why there are a few German terms in the code PokeCrafterC 7 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago

Didn't you answer your own question? Use variables. Make value instances for all the info then save to them and load from them so it's fast.bita how most inventory systems work, it takes too long to get foem datastores all the time and set them. Just set the datastores to the value of the value instances when the player is leaving and/or a manual save, always useful.

I hope this helps :3

0
Thanks! I had the variable in the loop and have now taken it out and it runs really fast! PokeCrafterC 7 — 2y
Ad

Answer this question