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

Can I save Datastore-info in variables or something?

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.

1 comment

0

I wanted to say that I actually speak German and that's why there are a few German terms in the code

1 answer

✓ Accepted answer

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

1 comment

0

Thanks! I had the variable in the loop and have now taken it out and it runs really fast!

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