I'm new to coding in roblox, and I've just put a playerdata save script in my game. The problem I'm having is where external scripts are supposed to update stats, the variables are being passed as booleans. I was doing math and everything was working, then it suddenly stopped and said I couldn't do math anymore.
the module script:
local PlayerStatManager = {} local DataStoreService = game:GetService('DataStoreService') local playerData = DataStoreService:GetDataStore('PlayerData') local AUTOSAVE_INTERVAL = 60 local sessionData = {} --the offending function --sudden shift to boolean for no reason function PlayerStatManager:ChangeStat(player, statName, changeValue) sessionData[player][statName] = sessionData[player][statName] + changeValue print(sessionData[player][statName]) end local function getPlayerData(player) return playerData:GetAsync(player.UserId) end local function savePlayerData(player) playerData:SetAsync(player.UserId, sessionData[player]) end local function setupPlayerData(player) local data = getPlayerData(player) if not data then sessionData[player] = {Money = 0, Experience = 0} savePlayerData(player) print('new player') else sessionData[player] = data print('existing user') print(sessionData[player]) end end local function autosave() while wait(AUTOSAVE_INTERVAL) do for player, data in pairs(sessionData) do savePlayerData(player) end end end game.Players.PlayerAdded:connect(setupPlayerData) game.Players.PlayerRemoving:connect(function(player) savePlayerData(player) sessionData[player] = nil end) spawn(autosave) return PlayerStatManager
the function in my update script:
game.Players.PlayerAdded:connect(function(player) while wait(2) do PlayerStatManager:ChangeStat(player, 'Money', 5) PlayerStatManager:ChangeStat(player, 'Experience', 5) end end)
the new error I'm getting:
12:27:02.727 - ServerStorage.playerData_Module:11: attempt to perform arithmetic on field '?' (a boolean value)
****EDIT Upon loading these exact scripts into a new place they work as expected, I get no errors and the saved values are changing. I have narrowed it down to this specific place as being broken.