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

DataStore script just saves 1thing?

Asked by 4 years ago

DataStoreService = game:GetService("DataStoreService") MyDataStore = DataStoreService:GetDataStore("DataStore1") MyDataStore2 = DataStoreService:GetDataStore("DataStore2") MyDataStore3 = DataStoreService:GetDataStore("DataStore3") game.Players.PlayerAdded:Connect(function(player) local stats = Instance.new("Folder",player) stats.Name = "leaderstats" local money = Instance.new("IntValue",stats) money.Name = "Potato" local values = Instance.new("Folder",player) values.Name = "Values" local sword = Instance.new("BoolValue",values) sword.Name = "Sword" sword.Value = false local speed = Instance.new("IntValue",values) speed.Name = "Speed" speed.Value = 16 local success, errormessage = pcall(function() data = MyDataStore:GetAsync(player.UserId.."-Potato") sword = MyDataStore2:GetAsync(player.UserId.."-Sword") speed = MyDataStore3:GetAsync(player.UserId.."-Speed") end) if success then money.Value = data speed.Value = speed sword.Value = sword print("Successfuly Loaded") else print("There's A Problem In Saving") warn(errormessage) end end) game.Players.PlayerRemoving:Connect(function(player) local success, errormessage = pcall(function() MyDataStore:SetAsync(player.UserId.."-Potato",player.leaderstats.Potato.Value) MyDataStore2:SetAsync(player.UserId.."-Sword",player.Values.Sword.Value) MyDataStore3:SetAsync(player.UserId.."-Speed",player.Values.Speed.Value) end) if success then print("Saved Successfuly") else print("There's A Problem In Saving") warn(errormessage) end end)

Please tell me what's the problem with this script? it just save the potato but sword and speed cannot be saved

Answer this question