My brain has been fried, how do i fix this error?

  1. What do you want to achieve? I want the booth to allow T-Shirts and gamepasses

  2. What is the issue? There’s a problem that i can’t replicate, but it happens with my friend. When i claim a booth, it works perfectly fine. But when my friend tries to do it, it pops up with a error

image

Ignore the workspace.API, player data and PathFindingMaker errors, they’re unrelated

  1. What solutions have you tried so far? We can’t think up on how the hell does this happen.

Here are the scripts that are involved in the error.

AssetScript:

local avatarService = game:GetService("AvatarEditorService")
local http = game:GetService("HttpService")
local events = game.ReplicatedStorage.Events

local playerData = {}

local avatarURL = "https://catalog.roproxy.com/v2/search/items/details?Category=3&CreatorName=%s"

-- gamepass
local gameURL = "https://games.roproxy.com/v2/users/%s/games?accessFilter=Public&limit=50"
local gamepassURL = "https://games.roproxy.com/v1/games/%s/game-passes?sortOrder=Asc&limit=10"

function getGamepasses(games)
	local completeList = {}
	
	for index, playerGame in pairs(games) do
		local gameGamepasses = http:JSONDecode(http:GetAsync(string.format(gamepassURL, playerGame.id))).data
		for _,gamepass in pairs(gameGamepasses) do
			gamepass["isGamepass"] = true
			table.insert(completeList, gamepass)
		end
	end
	return completeList
end

game.Players.PlayerAdded:Connect(function(plr)	
	local avatarItems = http:JSONDecode(http:GetAsync(string.format(avatarURL, plr.Name))).data
	local playerGames = http:JSONDecode(http:GetAsync(string.format(gameURL, plr.UserId))).data
	local playerGamepasses = getGamepasses(playerGames)
	
	playerData[plr.UserId] = {}
	local playerTable = playerData[plr.UserId]
	
	playerTable["avatarItems"] = avatarItems
	playerTable["playerGames"] = playerGames
	playerTable["playerGamepasses"] = playerGamepasses
end)

script.GetData.OnInvoke = function(userid, item)
	return playerData[userid][item]
end

StandHandler:

local tagService = game:GetService("CollectionService")

local booths = tagService:GetTagged("Booths")

for boothNumber:number, booth:Model in pairs(booths) do
	local userUI = booth:WaitForChild("UserInformation"):WaitForChild("UI")
	userUI.PlayerText.Text = "Unclaimed"
	userUI.AdText.Text = ""
	userUI.RecievedText.Text = ""
	userUI.DonationText.Text = ""
	local itemsScroller = booth:WaitForChild("DonationBoard"):WaitForChild("UI"):WaitForChild("List")

	local proximityPrompt = Instance.new("ProximityPrompt", booth:WaitForChild("MainPart") )
	proximityPrompt.HoldDuration = 1
	proximityPrompt.ActionText = "Claim"
	proximityPrompt.RequiresLineOfSight = false
	proximityPrompt.Name = "StandProximityPrompt"
	
	proximityPrompt.Triggered:Connect(function(plr)
		local avatarItems = game.ServerScriptService.AssetScript.GetData:Invoke(plr.UserId, "avatarItems")
		local gamepasses = game.ServerScriptService.AssetScript.GetData:Invoke(plr.UserId, "playerGamepasses")
		local items = {table.unpack(avatarItems), table.unpack(gamepasses)}
		
		table.sort(items, function(a, b)
			return a.price < b.price
		end)
		
		print("TableOfItems: ", items)
		
		if not items then return end
		
		for index,product in pairs(items) do
			--print(product)
			local butt = script.DonateButton:Clone()
			butt.Parent = itemsScroller
			butt.Text = string.format("%dR$", product.price)
			local id = Instance.new("IntValue", butt)
			id.Name = "ID"
			id.Value = product.id
			local gamepass = Instance.new("BoolValue", butt)
			gamepass.Name = "IsGamepass"
			if product.isGamepass == nil then product.isGamepass = false end
			gamepass.Value = product.isGamepass
		end
	end)
end

help

Did you try adding prints inside the PlayerAdded function? That would let us know up to what point the code is run.

Hey, from what I’ve found the error you’re describing happens when the player’s data doesn’t exist in the table which could be from it not being added on the player joining or you’re referencing a user who’s not in your server.

Here’s what my friend sent me after me adding the prints

sorry for the late reply

The GetData function was invoked while his gamepasses were in the middle of being loaded, so his player table wasn’t already added at the time of retrieving it.

What you could do is add a timeout parameter
to GetData like for WaitForChild() and make it repeatedly try to return it, a bit like how you would implement retries with datastores.

Alternatively, you could add a bindable event that is fired when the player table is ready and make the other scripts connect to it instead of on player added.

after some procrastination, i coded in the stuff, and now it shows this error

image
the first error insn’t relevant, he tried to claim it while it was loading.

help image

NEVERMIND, I JUST FIXED IT!!! turns out that the culprit was that gamepasses offsale did get searched up, and the prices of those gamepasses where nil, so the script errored out! Anyway, thanks for the help!