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

Data loss with DataStore?

Asked by 10 years ago

Right now im using a while true do loop that saves every 5 seconds but im having a lot of data loss

does it have something to do with the load script or with the save script?

here are the scripts im using right now

Load

01player = script.Parent.Parent.Parent.Parent
02 
03local Datastore = game:GetService("DataStoreService"):GetDataStore("OBJ")
04 
05local key = "player-"..player.userId
06 
07local savedObj = Datastore:GetAsync(key)
08 
09if savedObj then
10    Value1 = savedObj[1]
11    Value2 = savedObj[2]
12    Value3 = savedObj[3]
13else
14    local objToSave = {Value1, Value2,Value3}
15    Datastore:SetAsync(key, objToSave)
16end

Save

01player = script.Parent.Parent.Parent.Parent
02 
03local Datastore = game:GetService("DataStoreService"):GetDataStore("OBJ")
04 
05while true do
06    local key = "player-"..player.userId
07local objToSave = {Value1,Value2,Value3}
08    Datastore:SetAsync(key, objToSave)
09    wait(5)
10end

value1 value2 and value3 are just examples

anything wrong with my script?

1 answer

Log in to vote
0
Answered by 10 years ago

Shouldn't it be..

1if savedObj == nil then

?

0
above @centraltrain its the same thing as what the poster has iwilllandonmars 55 — 10y
Ad

Answer this question