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.
