Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

tostring not working? [Solved]

Asked by 9 years ago

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

01local part = script.Parent
02local model = part.Parent
03local running = false
04local wsChildren = workspace:GetChildren()
05 
06function onTouch(hit)
07    local h = hit.Parent:findFirstChild("Humanoid")
08    local hString = tostring(h.Parent)
09    if h ~= nil and not running then
10        running = true
11        for x = 1, #wsChildren do
12            if tostring(x):match(hString) ~= nil then --error occurs here
13                break
14            end
15        end
16    end
17end

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

0
use .Name theCJarmy7 1293 — 9y
0
h.Parent.Name theCJarmy7 1293 — 9y
0
That worked. Thanks! Vill1234 15 — 9y

Answer this question