Invalid argument #2 to 'match' (string expected, got table), Error

Hello devforum users, I am trying to make a script that’ll check if the name of the model matches with the name of the GUI and then set the value that matches with a table with sorts of numbers that’ll then match the number of the table via its name. Sort of basically a selecting system.

deployed = false
uis = nil
uis = game:GetService("UserInputService")
angle = 0
local placedprops = 0
cmort = 0
ss = game:GetService("ReplicatedStorage").Objects
current = 0
local temp
local player = game:GetService("Players").LocalPlayer
local equipped = false

local PressR = false
local PressT = false

script.Parent.Equipped:connect(function(m)
	equipped = true
	local guicloned2 = game.ReplicatedStorage.GUIDE:Clone()
	guicloned2.Name = "NewPlayerGUIGuide"
	guicloned2.Parent = player.PlayerGui
	
	local clonedGUI = game.ReplicatedStorage.ScreenGui:Clone()
	clonedGUI.Parent = player.PlayerGui
	
	if clonedGUI.ScrollingFrame.CLone.nameofprop.Text:match(mort) then
		clonedGUI.ScrollingFrame.CLone.select.Prop.Value = ss.Name
	end

	clonedGUI.ScrollingFrame.CLone.select.MouseButton1Click:Connect(function()
	end)
	
	guicloned2.Frame.amount.Text = placedprops .. "/500"
	
	uis = game:GetService("UserInputService")
	mouse = m		
	d = mouse.Button1Up:connect(dostuff)
	
	uis.InputBegan:Connect(function(keycode)
		if keycode.KeyCode == Enum.KeyCode.X and equipped == true then
			if mouse.Target.Parent.Name == "Placed by " .. player.Name then
				script.Parent.R:FireServer(mouse.Target.Parent)
				placedprops = placedprops - 1
			end
		end
	end)
	c = uis.InputBegan:connect(function(k)
		if k.KeyCode == Enum.KeyCode.R then
			if angle < 360 then
				angle = angle + 10
			else 
				angle = 0
			end
		elseif k.KeyCode == Enum.KeyCode.T then
			if angle > 0 then
				angle = angle - 10
			else
				angle = 360
			end
		elseif k.KeyCode == Enum.KeyCode.F then
			current = current - 1
			if current == -1 then
				current = 67
			end
			temp:destroy()
			setup()
		elseif k.KeyCode == Enum.KeyCode.G then
			current = current + 1
			if current == 68 then
				current = 0
			end
			temp:destroy()
			setup()
		end
	end)
	setup()
end)

script.Parent.Unequipped:connect(function() c:disconnect() d:disconnect() temp:destroy() player.PlayerGui:FindFirstChild("NewPlayerGUIGuide"):Destroy() player.PlayerGui:FindFirstChild("ScreenGui"):Destroy() equipped = false end)

function dostuff()
	if (temp.PrimaryPart.Position - game.Players.LocalPlayer.Character.Torso.Position).magnitude<20 then
		script.Parent.Place:FireServer(mort[current],ok)
		placedprops = placedprops + 1
		
		player.PlayerGui.NewPlayerGUIGuide.Frame.amount.Text = placedprops .. "/500"
	end
end

mort = {
	[0] = ss["Reinforced Wood Wall 1"],
	[1] = ss["Reinforced Wood Wall 2"],
	[2] = ss["Reinforced Wooden Plane"],
	[3] = ss["Wood Wall /w Door"],
	[4] = ss["FirePit"],
	[5] = ss["Sandbags"],
	[6] = ss["Sleeping Bag"],
	[7] = ss["Skeleton Corpse"],
	[8] = ss["Rusty Shelf"],
	[9] = ss["Table"],
	[10] = ss["Crate"],
	[11] = ss["Barrel"],
	[12] = ss["Bed"],
	[13] = ss["Laptop"],
	[14] = ss["Shopping Cart"],
	[15] = ss["Tree"],
	[16] = ss["Patch Of Dirt"],
	[17] = ss["Tent"],
	[18] = ss["Car"],
	[19] = ss["Keep Out Sign"],
	[20] = ss["Plant Box"],
	[21] = ss["M14"],
	[22] = ss["M4A1"],
	[23] = ss["AK47"],
	[24] = ss["Mounted MG34"],
	[25] = ss["Open Sign"],
	[26] = ss["Burger"],
	[27] = ss["Pot Plant"],
	[28] = ss["Condements 1"],
	[29] = ss["Condements 2"],
	[30] = ss["Plate"],
	[31] = ss["Ketchup & Mustard"],
	[32] = ss["AntiBulletWall"],
	[33] = ss["Abandonded Humvee"],
	[34] = ss["Windmill"],
	[35] = ss["Sandbag 2"],	
	[36] = ss["Lampshade"],
	[37] = ss["Lamp"],
	[38] = ss["Telescope"],
	[39] = ss["Pile Of Planks"],
	[40] = ss["Cargo"],	
	[41] = ss["AtomKick Case"],	
	[42] = ss["Guitar"],
	[43] = ss["Medical Case"],
	
	[44] = ss["Hanging Tent"],
	[45] = ss["Multipurpose Tent"],
	[46] = ss["Ladder"],
	[47] = ss["Tall Shelf"],
	[48] = ss["Dataserver"],
	[49] = ss["TV"],
	[50] = ss["Chair"],
	[51] = ss["Makeshift Fence"],
	[52] = ss["Palet Of Crates"],
	[53] = ss["ToolBox"],
	[54] = ss["Wood Table"],
	[55] = ss["Fridge"],
	[56] = ss["Haybale Stack"],
	[57] = ss["Pile of scrap"],
	
	[58] = ss["Scrap Ceiling/Platform"],
	[59] = ss["Scrap Ceiling/Platform XL"],
	[60] = ss["Scrap Ceiling Ladder"],
	[61] = ss["Scrap Doorway"],
	[62] = ss["Scrap Wall 1"],
	[63] = ss["Scrap Wall 2"],
	[64] = ss["Scrap Window 1"],
	[65] = ss["Scrap Wall 3"],
	[66] = ss["Reinforced Scrap Wall"],
	[67] = ss["Scrap Wall 4"],
}

function setup()
	temp = mort[current]:Clone()
	temp.Parent = workspace.CurrentCamera
	for i,v in pairs(temp:GetChildren()) do
		v.Transparency = 0.8
		v.CanCollide = false
	end
	mouse.TargetFilter = temp
	while wait() and temp do

		temp:SetPrimaryPartCFrame(CFrame.new(mouse.Hit.p)*CFrame.Angles(0,math.rad(angle),0))
		ok = temp.PrimaryPart.CFrame
	end
end

This script is responsible for the tables & other stuff

local PropCount = 0
local Children = game.ReplicatedStorage.Objects:GetChildren()
local Player = game.Players.LocalPlayer
local ss = game.ReplicatedStorage.Objects

function yes()
	local child2 = Player.PlayerGui.ScreenGui.ScrollingFrame:GetChildren()
	for i, child3 in ipairs(child2) do
		if child3.Name == "Clone" then
			child3:Destroy()
		end
	end
	for i, child in ipairs(Children) do
		if child:IsA("Model") then
			local NewClone = script.Parent.CLone:Clone()
			NewClone.Parent = Player.PlayerGui.ScreenGui.ScrollingFrame
			NewClone.nameofprop.Text = child.Name
			NewClone.Position = UDim2.new(0, 0, PropCount, 0)
			PropCount = PropCount + 0.01
			NewClone.Visible = true

		end
	end
end

yes()


mort = {
	[0] = ss["Reinforced Wood Wall 1"],
	[1] = ss["Reinforced Wood Wall 2"],
	[2] = ss["Reinforced Wooden Plane"],
	[3] = ss["Wood Wall /w Door"],
	[4] = ss["FirePit"],
	[5] = ss["Sandbags"],
	[6] = ss["Sleeping Bag"],
	[7] = ss["Skeleton Corpse"],
	[8] = ss["Rusty Shelf"],
	[9] = ss["Table"],
	[10] = ss["Crate"],
	[11] = ss["Barrel"],
	[12] = ss["Bed"],
	[13] = ss["Laptop"],
	[14] = ss["Shopping Cart"],
	[15] = ss["Tree"],
	[16] = ss["Patch Of Dirt"],
	[17] = ss["Tent"],
	[18] = ss["Car"],
	[19] = ss["Keep Out Sign"],
	[20] = ss["Plant Box"],
	[21] = ss["M14"],
	[22] = ss["M4A1"],
	[23] = ss["AK47"],
	[24] = ss["Mounted MG34"],
	[25] = ss["Open Sign"],
	[26] = ss["Burger"],
	[27] = ss["Pot Plant"],
	[28] = ss["Condements 1"],
	[29] = ss["Condements 2"],
	[30] = ss["Plate"],
	[31] = ss["Ketchup & Mustard"],
	[32] = ss["AntiBulletWall"],
	[33] = ss["Abandonded Humvee"],
	[34] = ss["Windmill"],
	[35] = ss["Sandbag 2"],	
	[36] = ss["Lampshade"],
	[37] = ss["Lamp"],
	[38] = ss["Telescope"],
	[39] = ss["Pile Of Planks"],
	[40] = ss["Cargo"],	
	[41] = ss["AtomKick Case"],	
	[42] = ss["Guitar"],
	[43] = ss["Medical Case"],

	[44] = ss["Hanging Tent"],
	[45] = ss["Multipurpose Tent"],
	[46] = ss["Ladder"],
	[47] = ss["Tall Shelf"],
	[48] = ss["Dataserver"],
	[49] = ss["TV"],
	[50] = ss["Chair"],
	[51] = ss["Makeshift Fence"],
	[52] = ss["Palet Of Crates"],
	[53] = ss["ToolBox"],
	[54] = ss["Wood Table"],
	[55] = ss["Fridge"],
	[56] = ss["Haybale Stack"],
	[57] = ss["Pile of scrap"],

	[58] = ss["Scrap Ceiling/Platform"],
	[59] = ss["Scrap Ceiling/Platform XL"],
	[60] = ss["Scrap Ceiling Ladder"],
	[61] = ss["Scrap Doorway"],
	[62] = ss["Scrap Wall 1"],
	[63] = ss["Scrap Wall 2"],
	[64] = ss["Scrap Window 1"],
	[65] = ss["Scrap Wall 3"],
	[66] = ss["Reinforced Scrap Wall"],
	[67] = ss["Scrap Wall 4"],
}

This script is what makes the stuff & yk…

1 Like
if clonedGUI.ScrollingFrame.CLone.nameofprop.Text:match(mort) then
	clonedGUI.ScrollingFrame.CLone.select.Prop.Value = ss.Name
end

It seems to gave a table instead of string, that’s what causes the error.

would I use table:find in this scenario?

It’s a dictionary so that function will not work, you’ve got to loop through, I made a little function here.

local function find(str: string)
	for index, instance in pairs(mort) do
		if instance.Name == str then
			return instance, index
		end
	end
end

I also don’t exactly get what you’re trying to do.

Sorry for being not active but im just trying to make a selecting system with props.
It works by when a new instance of gui is cloned it’ll match the name of the gui with one of the props under the mort table aswell as its number. There will be a number value under the new instance of the cloned gui that’ll match itself with the number under the mort table

There’s one thing I see! It may no be running because you put “CLone” and “Clone” here.

image
Its fine i just named the gui like that lol

1 Like

Heads Up, table.find does work with a dictionary I’ve tested it myself.