Manager.Profiles = {}
function Manager.AdjustMony(player: Player, amount: number)
local profile = Manager.Profiles[player]
if not profile then return end
profile.Data.mony = += amount
player.leaderstats.mony.Value = profile.Data.mony
end
return Manager
line of code that seems to cause it: profile.Data.mony = += amount
If anyone could help, it’d be greatly appreciated!
(mony is intentionally spelled wrong)
That error explains quite clearly what your problem is: You’re trying to add a number value to a value that doesn’t currently exist (nil). In the script you provided line number 8 is end so that error is located in a different script than the one you provided (or it might not be the whole script like @zahra_y735 suggested)
this is the only other script that handles the money
local ServerScriptService = game:GetService("ServerScriptService")
local Remotes = ReplicatedStorage.Remotes
local PlayerData = require(ServerScriptService.PlayerData.Manager)
local function Click(player: Player)
PlayerData.AdjustMony(player, 1)
end
Remotes.Click.OnServerEvent:Connect(Click)
I do think that the issue is due to the fact that your module doesn’t seem to be creating a new profile for the player if they don’t already have one, so I’ll see if I can re-write the module to fix that problem
Edit: @cozfl Here’s the new module. I’ve kept the name of the values the same but I changed the profile to work using the player’s UserId so that the data is saved if they exit and re-join the game:
local Manager = {}
Manager.Profiles = {}
function Manager.AdjustMony(player: Player, amount: number)
local profile = nil
if Manager.Profiles[player.UserId] then
profile = Manager.Profiles[player.UserId]
else
profile = {Data = {mony = 0}}
Manager.Profiles[player.UserId] = profile
end
profile.Data.mony += amount
player.leaderstats.mony.Value = profile.Data.mony
end
return Manager