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

Ahem. I am having problems with my NPC and I need help! Can someone please help me?

Asked by 5 years ago
Edited 5 years ago

The NPC just twerks around when it trys to walk through small hallways. It happens after i make i some "Light" part for the eyes (NOT SPOTLIGHT). I used WeldConstrait and I'm sure that it's all uncan collide. Please help me, I can't seems to fix it.

 function findNearestTorso(pos)
    local list = game.Workspace:GetChildren()
    local torso = nil
    local dist = 10
    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("Torso")
            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

local PathfindingService = game:GetService("PathfindingService")

local PATROL_DELAY = 0.5


local enemy = script.Parent
local humanoid = enemy.Humanoid
local humanoidRootPart = enemy.HumanoidRootPart

local pointA = game.Workspace:FindFirstChild("pointA")
local pointB = game.Workspace:FindFirstChild("pointB")
local pointC = game.Workspace:FindFirstChild("pointC")
local pointC1 = game.Workspace:FindFirstChild("pointC1")
local pointC2 = game.Workspace:FindFirstChild("pointC2")
local pointD = game.Workspace:FindFirstChild("pointD")
local pointE = game.Workspace:FindFirstChild("pointE")
local point = game.Workspace:FindFirstChild("point")


local currentDestination = pointA

while wait(PATROL_DELAY) do
    local startingPosition = humanoidRootPart.Position
    local goalPosition = currentDestination.Position

    local path = PathfindingService:FindPathAsync(startingPosition, goalPosition)
    local waypoints = path:GetWaypoints()

    for waypointIndex, waypoint in pairs(waypoints) do
        local waypointPosition = waypoint.Position
        humanoid:MoveTo(waypointPosition)
        humanoid.MoveToFinished:Wait()
    end 

    if currentDestination == pointA then
        currentDestination = pointB
    elseif currentDestination == pointB then
        currentDestination = pointC
    elseif currentDestination == pointC then
        currentDestination = pointC1
    elseif currentDestination == pointC1 then
        currentDestination = pointC2
    elseif currentDestination == pointC2 then
        local m = math.random(2)
        if m == 1 then
            currentDestination = pointD
        else
            currentDestination = pointE
        end
            elseif currentDestination == pointD then
        currentDestination = pointA
            elseif currentDestination == pointE then
        currentDestination = point
        elseif currentDestination == point then
        currentDestination = pointD
        elseif currentDestination == pointD then
        currentDestination = point
        elseif currentDestination == point then
        currentDestination = pointD
    end
end

script.Parent.Lighten.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        print("got em")
    end
end)
0
script plz User#23365 30 — 5y
0
it just a pathfinding script nothing wrong MineBlow111 39 — 5y
0
Just show us, maybe you did something wrong mixgingengerina10 223 — 5y
0
there MineBlow111 39 — 5y

Answer this question