Hello,
I am making an obby game, and I made a Datastore script that saves two values (more in the future), Stage and Skips. But when I tested the game, the stage value was saved perfectly fine, but the skips value was still at 0. Can anyone help?
local dataStoreService = game:GetService("DataStoreService")
local stageData = dataStoreService:GetDataStore("StageData")
local playerService = game:GetService("Players")
function saveTable(player)
local tableToSave = {
player.leaderstats.Stage.Value,
player.leaderstats.otherValues.Skips.Value
}
local success, result = pcall(function()
stageData:SetAsync(player.UserId, tableToSave)
end)
end
playerService.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr
local stage = Instance.new("IntValue")
stage.Name = "Stage"
stage.Parent = leaderstats
local otherValues = Instance.new("Folder")
otherValues.Name = "otherValues"
otherValues.Parent = leaderstats
local skips = Instance.new("IntValue")
skips.Name = "Skips"
skips.Parent = otherValues
local data
local success, err = pcall(function()
data = stageData:GetAsync(plr.UserId)
end)
if success and data then
stage.Value = data[1]
skips.Value = data[2]
end
end)
playerService.PlayerRemoving:Connect(function(plr)
local success, result = pcall(function()
saveTable(plr)
end)
end)