-
What do you want to achieve?
I want to create a function to adjust player stats based on an argument passed as opposed to a separate function for each stat. I have included a snippet of the code below. -
What is the issue?
The greyed out code is working correctly, but the second block of code is printing the level update from 1 to 2. then keeps printing 2. It doesn’t seem to be saving to the data store correctly. -
What solutions have you tried so far?
I’ve watched various profile service tutorials, searched the dev hub and tried asking in various discord groups.
I don’t think I understand the logic when converting
profile.Data.playerBaseStats.level += amount
to
profile.Data.playerBaseStats.*ArgumentPassed* += amount
I thought the playerBaseStats was a dictionary containing the [“StatName”] = value, so I tried to update the value in the dictionary, but I don’t believe profile service saves the data in the same way I initialize it.
--[[function module.AdjustLevel(player: Player, amount: number)
local profile = module.Profiles[player]
if not profile then return end
profile.Data.playerBaseStats.level += amount
RemoteEvents.Level:FireClient(player, profile.Data.playerBaseStats.level)
end
]]--
function module.AdjustPlayerBaseStats(player: Player, stat: string, amount: number)
local profile = module.Profiles[player]
if not profile then return end
local playerBaseStats = profile.Data.playerBaseStats
for i,v in pairs(playerBaseStats) do
if i == stat then
v += amount
print(i.." "..v)
end
end
end