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

Why does my NPC stop moving when its on the players head?

Asked by 4 years ago
Edited 4 years ago

The pathfinding script works ok, the big problem is that if the Player jumps on the bot's head, it will just stand still and do nothing. This also happens if the bot ends up on the players head. This is the script.

A gif of what happens when the player is on the bots head: https://gyazo.com/658f26c3f213198bb93d6d1b13c7291f

Another gif of the bot attacking the player when its on ground, but doing nothing when the player manages to jump onto its head: https://gyazo.com/d45ef6a021ed9a01ceaea612c13ce6f0

function findNearestTorso(pos)
    local list = game.Workspace:children()
    local torso = nil
    local dist = 1000
    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
            if string.match(temp2.Name, "Dummy") or string.match(temp2.Name, "dummy") or string.match(temp2.Name, "Gyro") then else
            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
    end
    return torso
end


coroutine.resume(coroutine.create(function()
print("the walk coroutine started")
while true do
    wait(0.3)
    local target = findNearestTorso(script.Parent.Torso.Position)
    if target ~= nil then
        script.Parent.Humanoid:MoveTo(target.Position, target)
    end
    end
end))

How can I edit this script so that when the player ends up on the bots head, the bot will adjust itself until the player falls off the bots head? I also want this to happen if the bot ends up on the players head. Any and all help is appreciated.

1 answer

Log in to vote
0
Answered by
emervise 123
4 years ago

Taking a quick glance at the problem and script I can take a guess at what your trying to achieve.

while wait(1) do
    if dummy.Head.YPosition < Torso.YPosition then
        -- make a new path with math.random. I would recommend using Humanoid.Jump as well. 
wait(0.5)
        if dummy.Head.YPosition < Torso.YPosition then
            -- repeat that code
        else
            break
        end
    end
end

If this is not what your looking for sorry.

Ad

Answer this question