Attempt to call table value

local SeekTargets = coroutine.create(function()
	local Part = Instance.new("WedgePart")
	Part.CanCollide = false
	Part.Transparency = 0.9
	Part.Size = Vector3.new(3, 30, 30)
	Part.Position = script.Parent.Position + script.Parent.CFrame.LookVector * Vector2.new(30,30).Magnitude
	Part.Orientation = script.Parent.Orientation + Vector3.new(0, 45, 90)
	Part.Anchored = true
	Part.Parent = workspace
	wait(0.1)
	local Parts = Part:GetTouchingParts()
	Part:Destroy()
	return Parts
end)

Why do i get this error?

1 Like

Which line is giving the error?

No idea, this is a part of the script and the only reaseon i can see the error is because i printed it out, this is the full script:

local SeekTargets = coroutine.create(function()
	local Part = Instance.new("WedgePart")
	Part.CanCollide = false
	Part.Transparency = 0.9
	Part.Size = Vector3.new(3, 30, 30)
	Part.Position = script.Parent.Position + script.Parent.CFrame.LookVector * Vector2.new(30,30).Magnitude
	Part.Orientation = script.Parent.Orientation + Vector3.new(0, 45, 90)
	Part.Anchored = true
	Part.Parent = workspace
	wait(0.1)
	local Parts = Part:GetTouchingParts()
	Part:Destroy()
	return Parts
end)

while true do
	local success , result = coroutine.resume(SeekTargets)
	print(success , result)
	if result and success == true then
		local ray = workspace:Raycast(script.Parent.Position , result[math.random(1,#result)].Position)
		script.Parent.Parent.Humanoid:Move(-ray.Direction)
	end
	wait(0.5)
end

Ah okay, could you try calling it as normal instead of in the coroutine? I’m looking over your script and I can’t see any instance of you calling a table value but maybe I’m skipping over something. You can put it back to a coroutine after.

if i don’t make it a coroutine nothing happens

It doesn’t even error if you don’t wrap it in a coroutine?

Im not sure if this is the exact issue, but i usually do a Coroutine in a separate variable such as

local function SeekTargets()
     --Blah blah blah
end
Coroutine1 = coroutine.create(SeekTargets);
1 Like

weird, i copied the coroutine and resumed it and nothing happened. no errors.

The error seems to only show up if the while loop is added

add a print after every line in the loop

how far does it go?

if result and success == true then

This line
Probably because result is a table lol

nope that’s not the issue :pensive:

I can’t use it in the statement at all, because i can’t check if the table has things in it because i get the error “Attempt to call a nil value”
How could i check if the table is empty then?

print(success, result)

if the if statement errors then what does that print?

either “true nil” or “false attempt to call a table value”
tables can be printed though im not sure about being used in if statements.

can you print Parts and see what happens?

empty table :shallow_pan_of_food:
I just need to place the table in an if statement but it yields an error

You need to connect a .Touched event to the part, otherwise :GetTouchingParts() will always return an empty table.

Ok, but do you know how i could place the table in an if statement? i . e: returns false if table is empty

that would explain why the last line wouldn’t work, but why aren’t the top two lines working for them?