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

AI not working ( RPG )?

Asked by 10 years ago

NOTE: NO ERRORS ARE IN THE DEVELOPERS LOG (f9) Basicly, My idea is when I walk away from my enemy , it returns back to its spawnpoint, so I created a block (ESpawn) and placed it in the character , so it knows the position. Now for some reason this only works in solo mode(studio), and they move to there positon, however , when I touch an enemy in normal play mode, they walk around anywhere, but I noticed they walk in my direction , they turn with me , but they carry on walking in a direction , but when I turn they turn, however I can see them glitching to move back to the spawn point , but something is making them move and turn with me? Weird right. Now the code.

while true do
    wait(0.1)
    local target = findNearestTorso(script.Parent.Torso.Position)
    if target ~= nil then
        script.Parent.Human:MoveTo(target.Position, target)
        else 
        script.Parent.Human:MoveTo(script.Parent.ESpawn.Position) --  this only works in solo mode, but glitches in normal play mode (ESpawn being the block to move to) when I take this out it works normally , but don't return to spawn pointof course.
    end
end

but there is something which makes the enemys turn with me..? Here is the code before it makes any difference:

local larm = script.Parent:FindFirstChild("Left Arm")
local rarm = script.Parent:FindFirstChild("Right Arm")

function findNearestTorso(pos)
    local list = game.Workspace:children()
    local torso = nil
    local     dist = 6
    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

If you understand this and you can help, thanks:)

0
This is a Script, and not a LocalScript, correct? Also, this would be a much clearer, simpler version of `findNearestTorso` (excepting that it doesn't require it be in any particular range, though, I would argue that behavior violates the name of the function) http://hastebin.com/ivabusanuq.lua  BlueTaslem 18071 — 10y
0
@BlueTaslem - Your Link does not work for me .. ( And yes it is a script not a localScript) ( The link is a blank page to hastebin) Bubbles5610 217 — 10y

Answer this question