Gosh darn nil values! Anyway, I am making a DataStore script to save completed quest and I am getting this error:
14:56:48.461 - Workspace.LoadQuestFolder:51: attempt to index upvalue 'DataStore' (a nil value) 14:56:48.461 - Stack Begin 14:56:48.461 - Script 'Workspace.LoadQuestFolder', Line 51 14:56:48.461 - Stack End
This is the script {It is a Normal Script, not Local or Module.}
local DataStore = game:GetService("DataStoreService"):GetDataStore("FolderStore") game.Players.PlayerAdded:connect(function(player) local folder = Instance.new("Folder") folder.Parent = player folder.Name = "CompletedQuests" local quest1 = Instance.new("BoolValue") quest1.Parent = folder quest1.Name = "QUEST1" local quest2 = Instance.new("BoolValue") quest2.Parent = folder quest2.Name = "QUEST2" local quest3 = Instance.new("BoolValue") quest3.Parent = folder quest3.Name = "QUEST3" local quest4 = Instance.new("BoolValue") quest4.Parent = folder quest4.Name = "QUEST4" local quest5 = Instance.new("BoolValue") quest5.Parent = folder quest5.Name = "QUEST5" local quest6 = Instance.new("BoolValue") quest6.Parent = folder quest6.Name = "QUEST6" local quest7 = Instance.new("BoolValue") quest7.Parent = folder quest7.Name = "QUEST7" local quest8 = Instance.new("BoolValue") quest8.Parent = folder quest8.Name = "QUEST8" local quest9 = Instance.new("BoolValue") quest9.Parent = folder quest9.Name = "QUEST9" local quest10 = Instance.new("BoolValue") quest10.Parent = folder quest10.Name = "QUEST10" local key = "player-"..player.userId local savedvalues = DataStore:GetAsync(key) if savedvalues then quest1.Value = savedvalues[1] quest2.Value = savedvalues[2] quest3.Value = savedvalues[3] quest4.Value = savedvalues[4] quest5.Value = savedvalues[5] quest6.Value = savedvalues[6] quest7.Value = savedvalues[7] quest8.Value = savedvalues[8] quest9.Value = savedvalues[9] quest10.Value = savedvalues[10] else local valuestosave = {quest1.Value, quest2.Value, quest3.Value, quest4.Value, quest5.Value, quest6.Value, quest7.Value, quest8.Value, quest9.Value, quest10.Value} DataStore:SetAsync(key, valuestosave) end end)
There is also the same error in the other script. This is the other script:
local DataStore = game:GetService("DataStoreService"):GetDataStore("FolderStore") game.Players.PlayerRemoving:connect(function(player) local key = "player-"..player.userId local valuestosave = {player.CompletedQuests.QUEST1.Value, player.CompletedQuests.QUEST2.Value, player.CompletedQuests.QUEST3.Value, player.CompletedQuests.QUEST4.Value, player.CompletedQuests.QUEST5.Value, player.CompletedQuests.QUEST6.Value, player.CompletedQuests.QUEST7.Value, player.CompletedQuests.QUEST8.Value, player.CompletedQuests.QUEST9.Value, player.CompletedQuests.QUEST10.Value} DataStore:SetAsync(key, valuestosave) end)
This is one of my first times using DataStores, so I do not understand what this error is. I did google it, But it didn't help.
The PlayerRemoving Event doesn't give the Script enough time to save all those Value so I suggest using a different method of saving like everytime the Player respawn or something. Here for example:
local DataStore = game:GetService("DataStoreService"):GetDataStore("FolderStore") game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(Char) local key = "player-"..player.userId local savedvalues = DataStore:GetAsync(key) local valuestosave = {player.CompletedQuests.QUEST1.Value, player.CompletedQuests.QUEST2.Value, player.CompletedQuests.QUEST3.Value, player.CompletedQuests.QUEST4.Value, player.CompletedQuests.QUEST5.Value, player.CompletedQuests.QUEST6.Value, player.CompletedQuests.QUEST7.Value, player.CompletedQuests.QUEST8.Value, player.CompletedQuests.QUEST9.Value, player.CompletedQuests.QUEST10.Value} DataStore:SetAsync(key, valuestosave) print("SavingValue") end) end)