Attempt to index 'nil' with UserId

Hello! I am making a script to get all the game passes of a user that they have created and put them on a scrollingframe. For some reason, i get the error ‘attempt to index ‘nil’ with UserId’. Before I got this error, the script didn’t work either. id like some help with this, thanks

local module = {}
local HttpService = game:GetService("HttpService")

local function get_next_page(request, cursor)
	local request_str = request.."&Cursor="..cursor
	
	local success, result = pcall(function()
		return HttpService:GetAsync(request_str)
	end)
	
	if success then
		return HttpService:JSONDecode(result)
	else
		warn(result)
		return {}
	end
end

function module.is_group_id(id)
	local request_str = "https://groups.roproxy.com/v1/groups/"..id
	local success, result = pcall(function()
		return HttpService:GetAsync(request_str, true)
	end)
	
	if success then
		return result.error == nil
	end
end

local function request(str, id)
	local success, result = pcall(function()
		return HttpService:JSONDecode(HttpService:GetAsync(str))
	end)

	local id_list = {}
	if success then
		local page = 1
		while result and page <=2  do
			local data = result.data
			if data then
				local cursor = result.nextPageCursor
				for _, item in ipairs(data) do
					table.insert(id_list, {item.id, item.price, item.name})
				end

				if cursor then
					page += 1
					result = get_next_page(str, cursor)
				else
					break
				end
			else
				break
			end
		end
	else
		warn("Couldn't get", id, "'s item list.")
		warn(result)
	end
	return id_list
end

function module.get_user_item_list(player)
	local request_str = "https://www.roproxy.com/users/inventory/list-json?assetTypeId=34&cursor=&itemsPerPage=100&pageNumber=1&userId="..player.UserId.."&Limit=30&MinPrice=2&SortType=4"
	if request_str ~= nil then
		return request(request_str)
	end
end

function module.get_group_item_list(group_id)
	local request_str = "https://catalog.roproxy.com/v1/search/items/details?Category=1&CreatorType=2&CreatorTargetId="..group_id.."&Limit=30&MinPrice=2&SortType=4"
	return request(request_str)
end

function module.get_item_list(id, Items)
	if module.is_group_id(id) then
		return module.get_group_item_list(id)
	else
		return module.get_user_item_list(Items)
	end
end

return module

At which line you are getting this error?

I am getting this error at line 64


You are not mentioning player instance in the get_user_item_list function arguments.

It says ‘Unknown Global player’ when i do that

Can you show me the script where you are calling .get_item_list function?

i dont see it in my code uh??? cuz i making a donation game and its supposed to appear on the stand but it doesn’t. i can send u the stand script if u want

Go to


Then search for:
image

1 Like
local module = {}
local ownerships = {}
local refresh_cooldowns = {}
local text_cooldowns, image_cooldowns, owner_cooldowns = {}, {}, {}
local connections = {}


local min_price_global = 1000

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TextService = game:GetService("TextService")

local modules = ReplicatedStorage.Modules
local data = require(script.Parent.Datastore)
local http_catalog = require(script.Parent.HttpCatalog)
local chat = require(script.Parent.Chat)
local shorten = require(modules.Shorten).shorten

local remotes = ReplicatedStorage.Remotes
local buttons_added_remote = remotes.ButtonsAdded
local purchase_remote = remotes.Purchase
local change_text_remote = remotes.ChangeStandText
local change_image_remote = remotes.ChangeStandImage
local change_owner_remote = remotes.ChangeStandOwner
local create_prompt_remote = remotes.EditProximityPrompt
local refresh_remote = remotes.RefreshListings

local stands = workspace.Stands

local function find_player_in_ownerships(player)
	local user_id = player.UserId
	for i, stand in ipairs(ownerships) do
		if stand[2] == user_id then
			return stand, i
		end
	end
end

local function filter_text(text, user)
	local result = TextService:FilterStringAsync(text, user.UserId)
	return result:GetNonChatStringForBroadcastAsync()
end

local function purchase_finished(player, product_id, was_purchased)
	if was_purchased then
		local product_info = MarketplaceService:GetProductInfo(product_id)
		local price = product_info.PriceInRobux
		local product_owner_id = product_info.Creator.CreatorTargetId
		local product_owner = Players:GetPlayerByUserId(product_owner_id)
		
		if player then
			data.add_donated(player, price)
		end
		
		if product_owner then
			data.add_raised(product_owner, price)
		end
		
		data.new_transaction()
		
		if price >= min_price_global then
			chat.SendToAll(string.upper(player.Name.." HAS DONATED "..shorten(price).." ROBUX TO "..product_info.Creator.Name.." !!"), "GLOBAL", false)
		else
			chat.Send(player.DisplayName.." has donated "..shorten(price).." ROBUX to "..product_info.Creator.Name.." !", "DONATION", false)
		end
	end
end

local function is_product_in_stand(stand_id, product_id)
	local products = ownerships[stand_id][3]
	for i, item in ipairs(products) do
		if item[1] == product_id then
			return i
		end
	end
	
	local owner = game.Players:GetPlayerByUserId(ownerships[stand_id][2])
	for i, item in ipairs(data.get_products(owner)) do
		if item[1] == product_id then
			return i
		end
	end
end

local function change_stand_text(player, text)
	local stand = find_player_in_ownerships(player)
	if stand then
		text = string.sub(text, 1, 150)
		if text_cooldowns[player.UserId] then
			if tick() - text_cooldowns[player.UserId] < 1 then
				return
			end
		end
		
		text = filter_text(text, player)
		stand[1].Text.Gui.TextLabel.Text = text
		data.set_text(player, text)
		text_cooldowns[player.UserId] = tick()	
	end
end

local function change_stand_image(player, id)
	local stand = find_player_in_ownerships(player)
	if stand then
		if image_cooldowns[player.UserId] then
			if tick() - image_cooldowns[player.UserId] < 1 then
				return
			end
		end
		if not string.find(tostring(id), "rbxassetid://") then
			id = "rbxassetid://"..id
		end
		stand[1].Text.Gui.ImageLabel.Image = id
		data.set_image(player, id)
		image_cooldowns[player.UserId] = tick()	
	end
end

local function change_stand_owner(player, id)
	local stand = find_player_in_ownerships(player)
	if stand then
		if owner_cooldowns[player.UserId] then
			if tick() - owner_cooldowns[player.UserId] < 1 then
				return
			end
		end

	
		stand[1].Owner.Value = id
		data.set_owner(player, id)
		owner_cooldowns[player.UserId] = tick()	
	end
end

local function purchase(player, stand_id, product_id)
	if player and stand_id and product_id then
		if ownerships[stand_id] then
			if is_product_in_stand(stand_id, product_id) then
				MarketplaceService:PromptPurchase(player, product_id)
			end
		end
	end
end

function module.refresh_listings(player)
	local stand, i = find_player_in_ownerships(player)
	if stand then
		if refresh_cooldowns[player.UserId] then
			if tick() - refresh_cooldowns[player.UserId] < 10 then
				return
			end
		end
		local listings_frame = stand[1].Listings.Gui.ScrollingFrame
		local onsale_items = http_catalog.get_item_list(data.get_owner(player))
		buttons_added_remote:FireAllClients(i, onsale_items)
		refresh_cooldowns[player.UserId] = tick()
		return onsale_items
	end
end

local function claim_prompt_triggered(player, i)
	if ownerships[i][2] == false then
		if not find_player_in_ownerships(player) then
			ownerships[i][2] = player.UserId
			local stand = ownerships[i][1]
			stand.Owner.Value = data.get_owner(player)
			create_prompt_remote:FireClient(player, i, data.get_products(player))
			stand.Claim.Claim.Enabled = false
			stand.Text.Gui.ImageLabel.Image = data.get_image(player)
			stand.Username.Gui.UsernameLabel.Text = player.DisplayName
			stand.Text.Gui.TextLabel.Text = data.get_text(player)
			stand.Raised.Gui.RaisedLabel.Text = "Raised R$".. shorten(data.get_raised(player))
			
			connections[player.UserId] = {}
			
			table.insert(connections[player.UserId], player.leaderstats.Raised.Changed:Connect(function()
				stand.Raised.Gui.RaisedLabel.Text = shorten(data.get_raised(player))
			end))
			
			
			local products = module.refresh_listings(player)
			ownerships[i][3] = products
		end
	end
end

function module.player_removing(player)
	local stand, i = find_player_in_ownerships(player)
	if stand then
		refresh_cooldowns[player.UserId] = nil
		buttons_added_remote:FireAllClients(i, {})		
		for _, connection in ipairs(connections[player.UserId]) do
			connection:Disconnect()
		end
		
		connections[player.UserId] = nil
		stand[1].Text.Gui.ImageLabel.Image = ""
		stand[1].Owner.Value = 0
		stand[1].Claim.Claim.Enabled = true
		stand[1].Username.Gui.UsernameLabel.Text = "Unclaimed"
		stand[1].Text.Gui.TextLabel.Text = ""
		stand[1].Raised.Gui.RaisedLabel.Text = ""
		stand[2] = false
		stand[3] = {}
	end
end

function module.player_added(player)
	for i=1, #stands:GetChildren() do
		local ownership = ownerships[i]
		if ownership then
			if ownership[2] then
				buttons_added_remote:FireClient(player, i, ownership[3])
			end
		end
	end
end

function module.initiate()
	chat.ChatColor("DONATION", Color3.fromRGB(255, 245, 130))
	chat.AddTag("DONATION", "💵")
	
	chat.ChatColor("GLOBAL", Color3.fromRGB(255, 101, 101))
	chat.AddTag("GLOBAL", "🌟")
	for i, stand in ipairs(stands:GetChildren()) do
		stand.Name = i
		ownerships[i] = {stand, false, {}}
		local owner = Instance.new("IntValue")
		owner.Name = "Owner"
		owner.Parent = stand
		local ClaimProximityPrompt = script.Claim:Clone()
		ClaimProximityPrompt.Parent = stand.Claim
		ClaimProximityPrompt.Triggered:Connect(function(player)
			claim_prompt_triggered(player, i)
		end)
		
	end
	change_text_remote.OnServerEvent:Connect(change_stand_text)
	change_image_remote.OnServerEvent:Connect(change_stand_image)
	change_owner_remote.OnServerEvent:Connect(change_stand_owner)
	MarketplaceService.PromptPurchaseFinished:Connect(purchase_finished)
	purchase_remote.OnServerEvent:Connect(purchase)
	refresh_remote.OnServerEvent:Connect(module.refresh_listings)
end

return module

Line 156

Oh, so at line 156 add another argument player.

http_catalog.get_item_list(data.get_owner(player),player)
                                                    ^^

What does this function returns?

image
is this what u mean

yeah, does this function return player? or its userid

how do i check that?? im not too sure


show me this module

local module = {}
local cached_data = {}
local saving = {}
local leaderboards = {}

local raised_total = 0
local donated_total = 0
local transactions_total = 0

local DatastoreService = game:GetService("DataStoreService")
local player_datastore = DatastoreService:GetDataStore("PlayerData")
local global_datastore = DatastoreService:GetDataStore("GlobalData")
local raised_datastore = DatastoreService:GetOrderedDataStore("LeaderboardRaised")
local donated_datastore = DatastoreService:GetOrderedDataStore("LeaderboardDonated")

local shorten = require(game.ReplicatedStorage.Modules.Shorten).shorten

function module.player_added(player)
	local key = player.UserId
	local data = player_datastore:GetAsync(key) or {}
	data.raised = data.raised or 0
	data.donated = data.donated or 0
	data.text = data.text or "Please donate !"
	data.owner = data.owner or player.UserId
	data.image = data.image or 0
	data.products = data.products or {}
	cached_data[key] = data
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	
	local raised = Instance.new("IntValue")
	raised.Name = "Raised"
	raised.Value = data.raised
	
	local donated = Instance.new("IntValue")
	donated.Name = "Donated"
	donated.Value = data.donated
	
	raised.Parent = leaderstats
	donated.Parent = leaderstats
	
	leaderstats.Parent = player
	
	local val = Instance.new("BoolValue")
	val.Name = "Loaded"
	val.Parent = player
end

function module.player_removing(player)
	local key = player.UserId
	if not saving[key] and player:FindFirstChild("Loaded") then
		saving[key] = true
		player_datastore:SetAsync(key, cached_data[key])
	end
	saving[key] = nil
end

function module.get_text(player)
	player:WaitForChild("Loaded")
	return cached_data[player.UserId].text
end

function module.get_image(player)
	player:WaitForChild("Loaded")
	return cached_data[player.UserId].image
end

function module.get_owner(player)
	player:WaitForChild("Loaded")
	return cached_data[player.UserId].owner
end

function module.get_products(player)
	player:WaitForChild("Loaded")
	return cached_data[player.UserId].products
end


function module.get_raised(player)
	player:WaitForChild("Loaded")
	return cached_data[player.UserId].raised
end

function module.get_donated(player)
	player:WaitForChild("Loaded")
	return cached_data[player.UserId].donated
end

function module.get_donated_total()
	return cached_data["Global"].donated
end

function module.get_raised_total()
	return cached_data["Global"].raised
end

function module.get_transactions_total()
	return cached_data["Global"].transactions
end

function module.new_transaction()
	transactions_total += 1
end

function module.add_raised(player, n)
	player:WaitForChild("Loaded")
	local key = player.UserId
	local leaderstats = player.leaderstats
	cached_data[key].raised += n
	raised_total += n
	leaderstats.Raised.Value = cached_data[key].raised
	refresh_guis()
end

function module.add_donated(player, n)
	player:WaitForChild("Loaded")
	local key = player.UserId
	local leaderstats = player.leaderstats
	cached_data[key].donated += n
	donated_total += n
	leaderstats.Donated.Value = cached_data[key].donated
	refresh_guis()
end

function module.set_product(player, i, id)
	player:WaitForChild("Loaded")
	if id then
		pcall(function()
			local info = game.MarketplaceService:GetProductInfo(id)
			if info then
				cached_data[player.UserId].products[i] = {id, info.PriceInRobux or 0, info.Name} 
			end
		end)
	else
		cached_data[player.UserId].products[i] = nil
	end
end

function module.set_text(player, text)
	player:WaitForChild("Loaded")
	local key = player.UserId
	cached_data[key].text = text
end

function module.set_image(player, id)
	player:WaitForChild("Loaded")
	local key = player.UserId
	cached_data[key].image = id
end

function module.set_owner(player, id)
	player:WaitForChild("Loaded")
	local key = player.UserId
	cached_data[key].owner = id
end

function module.refresh_leaderboard_raised(n)
	local leaderboard = {}
	n = n or 100
	n = math.clamp(n, 1, 100)
	
	for _, player in ipairs(game.Players:GetPlayers()) do
		local key = player.UserId
		raised_datastore:SetAsync(key, module.get_raised(player))
	end
	
	local success, result = pcall(function()
		return raised_datastore:GetSortedAsync(false, n, 1, 1e10)
	end)
	
	if success then
		local page = result:GetCurrentPage()
		for rank, value in ipairs(page) do
			leaderboard[rank] = {value.key, value.value}
		end
	end
	
	leaderboards[1] = leaderboard
	return leaderboard
end

function module.refresh_leaderboard_donated(n)
	local leaderboard = {}
	n = n or 100
	n = math.clamp(n, 1, 100)
	
	for _, player in ipairs(game.Players:GetPlayers()) do
		local key = player.UserId
		donated_datastore:SetAsync(key, module.get_donated(player))
	end
	
	local success, result = pcall(function()
		return donated_datastore:GetSortedAsync(false, n, 1, 1e10)
	end)

	if success then
		local page = result:GetCurrentPage()
		for rank, value in ipairs(page) do
			leaderboard[rank] = {value.key, value.value}
		end
	else
		warn(result)
	end

	leaderboards[2] = leaderboard
	return leaderboard
end

function module.get_leaderboard_raised()
	return leaderboards[1]
end

function module.get_leaderboard_donated()
	return leaderboards[2]
end

function module.get_raised_rank(player)
	local user_id = player.UserId
	for rank, data in ipairs(leaderboards[1]) do
		if data[1] == user_id then
			return rank
		end
	end
end

function module.get_donated_rank(player)
	local user_id = player.UserId
	for rank, data in ipairs(leaderboards[2]) do
		if data[1] == user_id then
			return rank
		end
	end
end

function module.server_closing()
	for _, player in ipairs(game.Players:GetPlayers()) do
		module.player_removing(player)
	end
	
	global_datastore:UpdateAsync("Global", function(old_data)
		old_data = old_data or {}
		local donated_t, raised_t, transac_t = old_data[1] or 0, old_data[2] or 0, old_data[3] or 0
		return {donated_t + donated_total, raised_t + raised_total, transac_t + transactions_total}
	end)
end

function stat(gui)
	local cdata = cached_data["Global"]
	gui.donated.Text = "Total donated robux: "..(cdata.donated + donated_total)
	gui.raised.Text = "Total raised robux: "..(cdata.raised + raised_total)
	gui.transactions.Text = "Total transactions: "..(cdata.transactions + transactions_total)
end

function refresh_guis()
	local _stats = workspace.stats
	local a,b = _stats.a, _stats.b
	stat(a.front)
	stat(a.back)
	stat(b.front)
	stat(b.back)
end

function module.initiate()
	local _stats = workspace.stats
	local a,b = _stats.a, _stats.b
	local data = global_datastore:GetAsync("Global")
	cached_data["Global"] = {
		donated = data[1] or 0,
		raised = data[2] or 0,
		transactions = data[3] or 0
	}

	refresh_guis()
end

function module.right_to_erasure(user_id)
	-- Erases user_id from every datastore in the game.
	local success, datastores_pages = pcall(function()
		return DatastoreService:ListDataStoresAsync()
	end)

	if success then
		while true do
			local datastores = datastores_pages:GetCurrentPage()
			for _, datastore in ipairs(datastores) do
				local success, err = pcall(function()
					datastore:RemoveAsync(user_id)
				end)

				if not success then
					warn(err, "\n", user_id, "———", datastore.Name)
				end
			end

			if datastores_pages.IsFinished then
				break
			end

			datastores_pages:AdvanceToNextPageAsync()
		end
	end

	print("————————\nErased", user_id, "\n————————")
end


return module

After line 156 can you add

print(data.get_owner(player).Name)

Oops my bad, add it before line 156.