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

I am making a piggy type of game and Ai pathfinding script broken. How can I fix it?

I am making a piggy form of game and my Ai pathfinding script is not working any way I can fix it? Here the script:

local Scientist = script.Parent
local humanoid = Scientist.Humanoid

local PathfindingService = game:GetService ("PathfindingService")

local function getPath(destination)
    local path = PathfindingService:CreatePath()

    path:ComputeAsync(Scientist.HumanoidRootPart, destination.Position)

    return path
end 

local function walkTo(destination)
    local path = getPath(destination)

    for index, waypoint in pairs(path:GetWaypoints()) do
        humanoid:MoveTo(waypoint.Position)
        humanoid.MoveToFinished:Wait()
    end
end

while true do
    walkTo(workspace.destination)
    walkTo(workspace.destination2)
end

2 comments

0

it would be pretty nice if you could tell us the error and which line it's on

0

its actually saying there is no error but he is not moving.

1 answer

✓ Accepted answer

Try This Maybe****

local larm = script.Parent:FindFirstChild("HumanoidRootPart")
local rarm = script.Parent:FindFirstChild("HumanoidRootPart")

function findNearestTorso(pos)
	local list = game.Workspace:children()
	local torso = nil
	local dist = 100000 -- distence for seeing player
	local temp = nil
	local human = nil
	local temp2 = nil
	for x = 1, #list do
		temp2 = list[x]
		if (temp2.className == "Model") and (temp2 ~= script.Parent) then
			temp = temp2:findFirstChild("HumanoidRootPart")
			human = temp2:findFirstChild("Humanoid")
			if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then
				if (temp.Position - pos).magnitude < dist then
					torso = temp
					dist = (temp.Position - pos).magnitude
				end
			end
		end
	end
	return torso
end

1 comment

0

thx but how would I change that for my model which is scientist

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