I have a problem with tostring. I keep getting the error: bad argument #2 to 'match' (string expected, got Object). My code is:

local part = script.Parent
local model = part.Parent
local running = false
local wsChildren = workspace:GetChildren()

function onTouch(hit)
	local h = hit.Parent:findFirstChild("Humanoid")
	local hString = tostring(h.Parent)
	if h ~= nil and not running then
		running = true
		for x = 1, #wsChildren do
			if tostring(x):match(hString) ~= nil then --error occurs here
				break
			end
		end
	end
end

I have also tried string.match but the same error happens.

3 comments

0

use .Name

0

h.Parent.Name

0

That worked. Thanks!