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

DataStoreSerice :GetAsync(key) dosen't work how to fix?

Asked by 6 years ago

Hello,
It stops working at :GetAsync(key) command and dosen’t prints the statements the output dosen’t shows any error. Here my script:

001local DS = game:GetService("DataStoreService")
002 
003local PetDS = DS:GetDataStore("PetDataStore1")
004 
005local PetDSValues = DS:GetDataStore("PetDataStore2")
006 
007local PetsTable = {}
008 
009local PetsValue = {}
010 
011local AUTOSAVE_INTERVAL = 60
012 
013   
014 
015game.Players.PlayerAdded:Connect(function(Player)
016 
017pcall(function()
018 
019PetsTable = {}
020 
021PetsValue = {}
022 
023local PetsFolder = Instance.new("Folder")
024 
025PetsFolder.Name = "Pets"
026 
027warn("owo")
028 
029PetsFolder.Parent = Player
030 
031local key = Player.UserId
032 
033PetsTable:GetAsync(key)
034 
035print("awa")
036 
037PetsValue:GetAsync(key)
038 
039print(PetsTable)
040 
041if PetsTable then
042 
043warn("decoding")
044 
045print(PetsTable)
046 
047local EncodedPetsTable = game.HttpService:JSONDecode(PetsTable)
048 
049local EncodedValueTable = game.HttpService:JSONDecode(PetsValue)
050 
051for _,p in pairs (EncodedPetsTable) do
052 
053local I = Instance.new("IntValue")
054 
055I.Name = EncodedPetsTable[p]
056 
057I.Value = EncodedValueTable[p]
058 
059I.Parent = PetsFolder
060 
061end
062 
063end
064 
065PetsTable = {}
066 
067PetsValue = {}
068 
069end)
070 
071end)
072 
073   
074 
075game.Players.PlayerRemoving:Connect(function(Player)
076 
077pcall(function()
078 
079local key = Player.UserId
080 
081PetsTable = {}
082 
083PetsValue = {}
084 
085for _,p in pairs (Player.Pets:GetChildren()) do
086 
087table.insert(PetsTable, p.Name)
088 
089table.insert(PetsValue, p.Value)
090 
091end
092 
093PetsTable = game.HttpService:JSONEncode(PetsTable)
094 
095PetsValue = game.HttpService:JSONEncode(PetsValue)
096 
097print(PetsTable)
098 
099print(PetsValue)
100 
101PetDS:SetAsync(key, PetsTable)
102 
103PetDSValues:SetAsync(key, PetsValue)
104 
105warn("saved")
106 
107end)
108 
109end)

Thanks for answers!

0
I'm not sure. However, PetsValue and PetsTable are not datascores. So how can you use :GetAsync on them? Tweakified 117 — 6y

Answer this question