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

This Code Saves Data, but it doesn't. Can anyone help?

Asked by 4 years ago
Edited 4 years ago

there are no errors and the game just wont save data

001local dataStore = game:GetService("DataStoreService"):GetDataStore("MyMiningData")
002local capacityEvent = game.ReplicatedStorage:WaitForChild("UICapacityEvent")
003local boughtRequest = game.ReplicatedStorage:WaitForChild("BoughtRequest")
004_G.boughtArray = {}
005local debugMode =true
006 
007function onSpawn(character)
008    local player = game.Players:GetPlayerFromCharacter(character)
009    local pickaxe = player:WaitForChild("Pickaxe").Value
010    local backpack = player:WaitForChild("BackpackItem").Value
011    local newPickaxe = game.ReplicatedStorage:FindFirstChild(pickaxe):Clone()
012    newPickaxe.Parent = player.Backpack
013    local newBackpack = game.ReplicatedStorage:FindFirstChild(backpack):Clone()
014    player.Character.Humanoid:AddAccessory(newBackpack)
015    local capacity = newBackpack.Capacity.Value
View all 184 lines...

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

When you save the data, embed it in a pcall. For example:

01game.Players.PlayerAdded:connect(function(player)
02    local success, err = pcall(function()
03        datastore:SetAsync(key,value)
04    end)
05    if success then
06    print("Success!")
07    elseif not success and err then
08    print("Error: "..err)
09    end
10end)
Ad

Answer this question