Im trying to save 3 values; 2 in startergui that are IntValues, and one BoolValue inside ReplicatedStorage.
local DataStoreService = game:GetService("DataStoreService") local inventory = DataStoreService:GetDataStore("Inventory") local values = game.StarterGui.ShopValues.FirstWalkspeed local koalaInv = game.StarterGui.HatValues.KoalaInventoryCount local koalaQue = game.StarterGui.QuestHolder.KoalaCount game.Players.PlayerAdded:Connect(function(player) local Data local Data2 local Data3 local success, err = pcall(function() Data = inventory:GetAsync(player.UserId.."-WalkSpeed", values.Value) Data2 = inventory:GetAsync(player.UserId.."-KoalaInv", koalaInv.Value) Data3 = inventory:GetAsync(player.UserId.."-KoalaQuest", koalaQue.Value) end) if success then values.Value = Data koalaInv.Value = Data2 koalaQue.Value = Data3 else print("Error getting data") warn(err) end end) game.Players.PlayerRemoving:Connect(function(player) local success, err = pcall(function() inventory:SetAsync(player.UserId.."-WalkSpeed", values.Value) inventory:SetAsync(player.UserId.."-KoalaInv", koalaInv.Value) inventory:SetAsync(player.UserId.."-KoalaQuest", koalaQue.Value) end) if success then print ("data saved") else print("There was an error") warn(err) end end)
Hello.
Problem:
You tried setting the DataStore multiple times at once. This wouldn't work as DataStore's are designed to store 1 value.
Solution:
Instead, save a table containing the values.
Fixed Code:
local DataStoreService = game:GetService("DataStoreService") local inventory = DataStoreService:GetDataStore("Inventory") local values = game.StarterGui.ShopValues.FirstWalkspeed local koalaInv = game.StarterGui.HatValues.KoalaInventoryCount local koalaQue = game.StarterGui.QuestHolder.KoalaCount game.Players.PlayerAdded:Connect(function(player) local Data local success, err = pcall(function() Data = inventory:GetAsync(player.UserId.."_Data", values.Value) end) if success then values.Value = Data[1] koalaInv.Value = Data[2] koalaQue.Value = Data[3] else print("Error getting data") warn(err) end end) game.Players.PlayerRemoving:Connect(function(player) local toSave = {values.Value, koalaInv.Value, koalaQue.Value} local success, err = pcall(function() inventory:SetAsync(player.UserId.."-Data", toSave) end) if success then print ("data saved") else print("There was an error") warn(err) end end)