I’m having this error message from this function whenever I call it
function GameFramework:AddToPlayerData(player, storeName, key, amount)
local dataStore = self.DataStore[storeName]
if not dataStore then
warn("DataStore not initialized: " .. storeName)
return
end
local success, err = pcall(function()
local rawData = dataStore:GetAsync(player.UserId)
local data = httpService:JSONDecode(rawData)
print("Before update:", data)
if type(data[key]) ~= "number" then
data[key] = 0
end
data[key] = data[key] + amount
print("After update:", data)
local serializedData = httpService:JSONEncode(data)
dataStore:SetAsync(player.UserId, serializedData)
local dataFolder = player:FindFirstChild("data")
if dataFolder then
local valueInstance = dataFolder:FindFirstChild(key)
if valueInstance and valueInstance:IsA("NumberValue") then
valueInstance.Value = data[key]
else
local newValue = Instance.new("NumberValue")
newValue.Name = key
newValue.Value = data[key]
newValue.Parent = dataFolder
end
end
end)
if not success then
warn("Failed to add to data for player: " .. player.Name .. " - " .. err)
end
end
The error message Is: argument #1 expects a string, but table was passed from this line:
local data = httpService:JSONDecode(rawData)