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

My pathfinding script is getting a error "Unable to cast double to Vector3"?

Asked by 2 years ago

Im making it so whenever this AI sees me it will start to chase me and there is to scripts im using for this 1. Making him walk around randomly this isnt the script getting the error

-----------------
--Walking Randomly AI

local human = script.Parent:WaitForChild("Humanoid")
local torso = script.Parent:WaitForChild("Torso")

local clone = script.Parent:Clone()

--[[local pathArgs = {
    ["AgentHeight"] = 5,
    ["AgentRaidus"] = 2, 
    ["AgentCanJump"] = true
}--]]

function move()
    local randX = math.random(-20,20)
    local randZ = math.random(-20,20)
    local goal = torso.Position + Vector3.new(randX,0,randZ)

    local path = game:GetService("PathfindingService"):CreatePath()
    path:ComputeAsync(torso.Position, goal)
    local waypoints = path:GetWaypoints()

    if path.Status == Enum.PathStatus.Success then
        for _, waypoint in pairs(waypoints) do
            if waypoint.Action == Enum.PathWaypointAction.Jump then
                human.Jump = true
            end
            human:MoveTo(waypoint.Position)
            human.MoveToFinished:Wait(2)
        end
    else
        print("Path unsuccessful B")
        wait(2)
    end
end

human.Died:Connect(function()
    wait(5)
    clone.Parent = workspace
    game:GetService("Debris"):AddItem(script.Parent,0.1)
end)

local BAIC = game.Workspace.bily117AI
while wait(3) do
    if BAIC.Switch == false then
        break
    end
    move() 
end


and then 2. The region3 script that im making so when a player touches it the AI will chase them and this is the script with the error

---------------------
--Region

local RegionPart = game.Workspace.RegionPart1
local pos1 = RegionPart.Position - (RegionPart.Size / 2)
local pos2 = RegionPart.Position + (RegionPart.Size / 2)
local region = Region3.new(pos1, pos2)

local part  = Instance.new("Part")

part.Anchored = false
part.Size = region.Size
part.Parent = game.Workspace
part.CanCollide = false
part.BrickColor = BrickColor.new("Really red")
part.Transparency = 0.7
part.Position = game.Workspace.RegionPart1.Position
part.Name = ("part")

local weld = Instance.new("Weld")
weld.Part0 = part
weld.Part1 = game.Workspace.RegionPart1
weld.Parent = part

local partt = game.Workspace:WaitForChild("part")
partt.Touched:Connect(function(hit)
    if hit.Parent and hit.Parent:FindFirstChild("Humanoid") then

        print("Checkpoint 1")

        local BAIC = game.Workspace:WaitForChild("bily117AI")
        local BAICH = BAIC:WaitForChild("Humanoid")
        local BAICT = BAIC:WaitForChild("Torso")
        local switch = BAIC:FindFirstChild("Switch")
        switch = false
            while true do
                wait(1)
                if BAIC.Switch == true then
                    break
                end

            print("Checkpoint 2")

            local Humanoid = hit.Parent         
            local goal = (BAICT.Position - Humanoid.Torso.Position).magnitude
            print(goal)
            local path = game:GetService("PathfindingService"):CreatePath()
            path:ComputeAsync(BAICT.Position, goal)
            local waypoints = path:WayPoints()

            if path.Status == Enum.PathStatus.Success then
                for _, waypoint in pairs(waypoints) do
                    if waypoint.Action == Enum.PathWaypointAction.Jump then
                        BAICH.Jump = true
                    end
                    BAICH:MoveTo(waypoint.Position)
                    BAICH.MoveToFinished:Wait(2)
                end
            else
                print("Path unsuccessful B")
                wait(2)
            end
        end
    end
end)

awnser asap if u can, my discord is bily117#5405 if u wanna dm me about it

0
On line 45, (BAICT.Position - Humanoid.Torso.Position).magnitude returns a number value representing the magnitude or length between the two vectors. On line 48, you attempt to use the magnitude value in place of the 'finish' Vector3 parameter. Yes, it does require a Vector3 value in the second parameter. appxritixn 2235 — 2y

Answer this question