Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Pathfinding String expected got object help?

So I keep getting the error

''Workspace.MovingSharks.Script:9: bad argument #2 to '?' (string expected, got Object)"

I've tried and tried again but to avail, What's wrong?

local movingpeices = script.Parent.MoveToPieces:GetChildren()
local sharks =script.Parent:GetChildren() 

while wait() do
	wait(1)
	for i,v in pairs (sharks) do
		if script.Parent.Shark.Name == "Shark" then
			local target = movingpeices[math.random(1, #movingpeices)]
			local path = game:GetService("PathfindingService"):ComputeRawPathAsync(script.Parent.Shark.Torso.Position, target.Position, 500)
			local points = path:GetPointCoordinates()
			if path.Status == Enum.PathStatus.Success or Enum.PathStatus.ClosestNoPath then
			repeat wait() until points ~= nil
				for i = 1, #points do
					script.Parent.Shark.Humanoid:MoveTo(points[i])
				end
			end
		end
	end
end

1 answer

You need to use the Object's name in the square brackets, rather than the object itself. You're doing script.Parent[v], you need to do script.Parent[v.Name].

3 comments

0

Nevermind, the script box had cut off half of the line, heh.

0

lol

0

v.Name, you are searching for an object through the square brackets, you need to search the object's name. Also, you might end up grabbing the script in the "local sharks" variable.

This discussion is preserved as it was. New answers, comments, and votes are closed.