Variable is a string but errormessage says its a instance

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

i want to make a function where you buy robux to put your asset in here

  1. What is the issue? Include screenshots / videos if possible!

the issue is that variable “cursor” is a string, but the error message says its a instance. Do i have to refresh roblox studio?

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

idk

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local Market = game:GetService("MarketplaceService")
local HTTPService = game:GetService("HttpService")

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local EventsFolder = ReplicatedStorage:FindFirstChild("ProductEvents")

game.Players.PlayerAdded:Connect(function(plr)
	local PF = Instance.new("Folder", plr)
	PF.Name = "ProductFolder"
	local HttpService = game:GetService("HttpService")

	local CanSeeInventory = "https://inventory.roproxy.com/v1/users/"..plr.UserId.."/can-view-inventory"
	local Response = HttpService:RequestAsync({
		Url = CanSeeInventory,
		Method = "GET"
	});
	if Response.Success then -- If it doesnst work, then idk	
		local Body = HttpService:JSONDecode(Response.Body) -- Decoding the table
		if Body.canView == true then

			local function CloneAssets(Gui, Contents, Template)
				for _, player in pairs(game:GetService("Players"):GetPlayers()) do
					for _, Asset in pairs(Contents) do
						local data = Market:GetProductInfo(Asset, Enum.InfoType.Asset)
						if data and data.IsForSale then
							local Gui = Template:Clone()
							Gui.Parent = Gui
							Gui.Name = table.find(Contents, Asset)
							Gui.PurchaseButton.Text = data.PriceInRobux .. "$"
							Gui.Visible = true
							Gui.ImportantValues:FindFirstChild("AssetId").Value = Asset
						end
					end
				end
				for _, Asset in ipairs(Contents) do
					local data = Market:GetProductInfo(Asset, Enum.InfoType.Asset)
					if data and data.IsForSale then
						local MainGui = Gui
						MainGui.Name = table.find(Contents, Asset)
						MainGui.PurchaseButton.Text = data.PriceInRobux .. "$"
						MainGui.Visible = true
						MainGui.ImportantValues:FindFirstChild("AssetId").Value = Asset
					end
				end
			end


			local SubCategories = {
				"2";
				"11";
				"12"
			}

			local function GetContent(username, userid, tshirts, cursor)
				for i = 1,3 do
					local Contents = {}
					cursor = cursor or ""

					local Url = "https://catalog.roproxy.com/v1/search/items/details?Category=3&Subcategory=".. SubCategories[i].. "&Sort=4&Limit=30&CreatorName=%s&cursor=%s"
					local requestUrl = Url:format(username, cursor)

					local success, result = pcall(function()
						return HTTPService:GetAsync(requestUrl, true)
					end)

					if success then
						if result then
							local success2, result2 = pcall(function()
								return HTTPService:JSONDecode(result)
							end)
							local suc, er = pcall(function()
								for _, tshirt in ipairs(result2.data) do
									table.insert(Contents, tshirt.id)
								end
							end)
							if not suc then
								warn(er)
							end
							return Contents
						end
					end
				end
			end



			EventsFolder:WaitForChild("SetAsset").OnServerEvent:Connect(function(username, userid)
				local Boothname, Contents = GetContent(username, userid)
				if Contents then
					CloneAssets(plr.PlayerGui.LiveDonationScreen.Main.ProductFrame, Contents, plr.PlayerGui.LiveDonationScreen.Main.ProductFrame.Layout)
				end
			end)
			
		else
			game.ReplicatedStorage:WaitForChild("ProductEvents"):WaitForChild("WarnPlayer"):FireClient(plr)
		end
	end
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like

the error is the quote above…

cursor is string but the error says its a instance what do i do

Here’s where you went wrong I think.

i put cursor = "" but it still wont work

Aha! I see your issue now. Change the ‘local cursor’ to ‘local Cursor’; you’ve got two variables with the same name so Lua doesn’t know which to pick.

The first variable passed into a RemoteEvent’s OnServerEvent is always the player that fired said event. Change that to

EventsFolder:WaitForChild("SetAsset").OnServerEvent:Connect(function(player, username, userid)

why does this error form when i did your solution:
ServerScriptService.ProductFolder:60: invalid argument #2 to ‘format’ (string expected, got Instance)

it works but the products are not shown…

it might be a bug, But I won’t ask you to try and solve it because it’s going to be off topic

tbh the error is on arg 1 not arg 2 why does it says arg 2