So, I am trying to save a magic level inside of a folder inside of a player using DataStore2, and it's giving me the error that magicLevel is a nilValue?
This Is A Server Script Inside Of ServerScriptService
local defaultMagicLevel = 1
local DataStore2 = require(1936396537)
local MainKey = "MainKey"
DataStore2.Combine(MainKey, "Stats")
local function SetDataTable()
local userData = {
Stats = {
magicLevel = 1
}
}
return userData
end
game.Players.PlayerAdded:Connect(function(plr)
local userData = DataStore2(MainKey,plr):Get(SetDataTable())
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
local magicLevel = Instance.new("IntValue")
magicLevel.Value = defaultMagicLevel
magicLevel.Name = "Level"
local statsData = DataStore2("Stats",plr)
local function updateStats(updatedValue)
magicLevel.Value = statsData:Get(updatedValue).magicLevel
end
updateStats(userData.Stats)
statsData:OnUpdate(updateStats)
leaderstats.Parent = plr
magicLevel.Parent = leaderstats
userData.Stats.magicLevel = userData.magicLevel + 1
statsData:Set(userData.Stats)
end)
Error:
21:43:55.602 - ServerScriptService.Stats:39: attempt to perform arithmetic on field 'magicLevel' (a nil value) 21:43:55.603 - Stack Begin 21:43:55.604 - Script 'ServerScriptService.Stats', Line 39 21:43:55.605 - Stack End
Any Database Wizards?

1 comment
This isn't free model (DS2) support