Why is this "table" trying to be a string & table at the same time

im trying to make a table that has a bunch of items from the catalogue in it, but when i put it in pairs, it tells me, “Table expected, got string” and when i use string:separate it says “String expected, got table”

it just wont make up its mind!!

image
image

script

local event = game.ReplicatedStorage.Events.InsertModels
local marketplaceservice = game:GetService("MarketplaceService")

local insertservice = game:GetService("InsertService")
local assetservice = game:GetService("AssetService")

local Http = game:GetService("HttpService")

local AssetTypes = {
	["Hat"] = 9,
	["Shirt"] = 12,
	["Pants"] = 14
}

local url = "https://catalog.roproxy.com/v2/search/items/details?Subcategory="..AssetTypes["Hat"].."&SortType=0&SortAggregation=5&Limit=30"

local pages = 25

local assets = {}


event.OnServerEvent:Connect(function(player,idx)
	print("created")
	for i = 1, pages do
		local response = Http:GetAsync(url)..tostring(i)
		local data = Http:JSONEncode(Http:GetAsync(url))
		data = Http:JSONDecode(data)
		
		print(data)
		
		repeat wait(1)
			print("hi")
			if typeof(data) ~= table then
				print("the type of data is "..typeof(data))
				data = string:split(',')
			end
		until
		typeof(data) == table
		
		for _, asset in pairs(data) do
			print("start")
			
			local name = asset.Name
			local id = asset.AssetId
			assets[#assets + 1] = "{Id = " ..id .. ", Name = \"" .. name .. "\"}"
			print(name)
		end
		print(i)
	end

	local source = "return { \n\t" .. table.concat(assets, ",\n\t") .. "\n}"
	print(source)
end)
1 Like

ok my friend sent me a devforum post that basically says "its not string:split its string.split and that fixed it. i hate game development

The colon is usable too.

local str = "hello world"

local split1 = string.split(str, " ")
local split2 = str:split(" ")
print(split1, split2) --> same result

: passes the calling string as an argument implicitly (think self in OOP).

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.