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

Can you have a loop with GetAsync in it?

I heard that it caches, but would that be specific to a certain value?

weapons = {"Shotgun","OrcBlade"}

for i,v in pairs(weapons) do

local DataStore = game:GetService("DataStoreService"):GetDataStore(v)

local key = newPlayer.userId..v

if DataStore:GetAsync(key) == true then
points.Value = points.Value+999
else
print("weapon not owned")
end
end

It adds 999 points, but not the other 999 and I have the OrcBlade save scripted so it saves as newPlayer.userId.."OrcBlade"

1 answer

Line 9 would be ~= nil, as :GetAsync returns a value, not a boolean. If there is no value for the key, it returns nil. Of course, if you set the key's value to false beforehand, don't change it.

As for your question, yes this would work. I assume you're using this to see if a player owns a certain weapon, and if so they are awarded a lot of points. However, keep in mind that :GetAsync() caches the returned value for about 10 seconds, as this may affect the script if you build off of it.

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