Hello! I'm testing out a few module scripts to try and better understand how they work. I went through the steps on the guide for this one: https://developer.roblox.com/articles/Saving-Player-Data This is what I had issues with when I types it out:
function PlayerStatManager:ChangeStat(player, statName, value) assert(typeof(sessionData[playerUserId][statName]) == typeof(value), "ChangeStat error: types do not match") local playerUserId = "Player_" .. player.UserId if typeof(sessionData[playerUserId][statName]) == "number" then sessionData[playerUserId][statName] = sessionData[playerUserId][statName] + value else sessionData[playerUserId][statName] = value end end
I really don't understand this part, and I keep getting the ChangeStat error or other errors when I do it:
assert(typeof(sessionData[playerUserId][statName]) == typeof(value), "ChangeStat error: types do not match")
Can someone help me understand what this is for? Is it needed? If so what is it used for and what might I be doing wrong? If I just remove that line, it seems to work - the value changes just fine. Thank you!
Hey, i am learning to work with data stores too, right now, and im also using this article as base, but i am getting an error in the "setupPlayerData" funtion when it tries to get
local data = playerData:GetAsync(playerUserId)
the error says
502: API Services rejected request with error. HTTP 403 (Forbidden)
It is very mysterious to me why the fuck this is happening. If it happens to you too pls advise me so i'm sure it is not my code. Else I looked about this error and it only use to happen when API services or HTTP requests are disabled or when the dev is on teamcreate, and that's none of them my case. I read that sometimes this errors show up for some time randomly, but im affraid it never goes out cause it is like this since yesterday.
Pls feedback me if you are getting this error too (if you already scripted that part)!
And about your question, looks like it is already answered, the purpose of that code is to check if the value you are saving in the table is of the same type than the value that is already there (number, string, object, etc), so it will prevent you from making something like:
sessionData["ColorOfHead"] = sessionData["ColorOfHead"] + 1
-- and get an error
-- so if is not a number, it will update the data like this:
sessionData["ColorOfHead"] = "String"