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

Can someone help me make a following monster?

Asked by 7 years ago

I am trying to make a following npc, can someone help me? I am a beginner scripter and this is my first time trying to make a following script and cant figure out how plz help :C

0
just go to tools and type in "zombie" or something sweetlittlegirlohhl -22 — 7y
0
not helpful, i dont take free models lukebloxdaily 6 — 7y

2 answers

Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

There

local list = game.Workspace:children() 
local dist = 500 -- Change to the distance you want the Zombie to find people
local time = 0.1 --Change to how long you want the Zombie to find and chase people (I recommend 0.1)

while true do wait(time)
    for x = 1, #list do
        local temp2 = list[x]
        if (temp2.className == "Model") and (temp2 ~= script.Parent) then
          local temp = temp2:findFirstChild("Torso")
           local human = temp2:findFirstChild("Humanoid")
            if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then
                if (temp.Position - script.Parent.Torso.Position).magnitude < dist then
                 script.Parent.--[[Zombies//Change to name of whatever you put this into]]:MoveTo(temp.Position, temp)
                end             --Then remove the text and these: -- [[ ]]
            end
        end
    end
end 

0
thx, so i put this straight in the model? (model is da zombie) lukebloxdaily 6 — 7y
0
it doesnt work, rip Dx lukebloxdaily 6 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

Here try this, make sure it's in a model with a Humanoid, and also make sure the model is not anchored.

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 = 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
            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




while true do
    wait(0.1)
    local target = findNearestTorso(script.Parent.Torso.Position)
    if target ~= nil then
        script.Parent.Humanoid:MoveTo(target.Position, target)
    end

end 

Answer this question