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

Pathfinding String expected got object help?

Asked by
NotSoNorm 777 Moderation Voter
8 years ago

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

Log in to vote
0
Answered by 8 years ago

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].

0
Nevermind, the script box had cut off half of the line, heh. darkelementallord 686 — 8y
0
lol NotSoNorm 777 — 8y
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. darkelementallord 686 — 8y
Ad

Answer this question