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

How do I create a follow script for an Enemy NPC that choose the users around? [closed]

Asked by 6 years ago
Edited 6 years ago

I'm making a RPG game and I don't know how to make an enemy NPC that follow and kill players. If have anyone know that, please help me. I have try to run this script in Roblox Studio but it not do anything. This is my script code I don't know how to fix it:

01players = nil; --Where we are going to store all the players
02dummy = game.Workspace.Dummy; --Dummy reference
03currentPlayerFollowing = nil; --The current player the zombie is following
04damage = 2; --Change this for more damage if you want
05 
06function touched(hit)
07  --pcall allows for errors to be disregarded so you don't have to worry about random output errors
08   if pcall(function() if hit.Parent.Humanoid ~= nil then end end) then --If the character's health storage is there
09   pcall(function() hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - damage end); --Do damage
10   end
11end
12 
13dummy.Torso.Touched:connect(touched);
14 
15while wait(1) do --Forever loop
View all 27 lines...

What happend with this? Please help me! Thank for your help.

0
You don’t know how to fix it cause it’s not yours. User#19524 175 — 6y

Closed as Not Constructive by User#19524, T0XN, and evaera

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

1 answer

Log in to vote
0
Answered by 6 years ago

Try this:

01local larm = script.Parent:FindFirstChild("HumanoidRootPart")
02local rarm = script.Parent:FindFirstChild("HumanoidRootPart")
03 
04function findNearestTorso(pos)
05    local list = game.Workspace:children()
06    local torso = nil
07    local dist = 45
08    local temp = nil
09    local human = nil
10    local temp2 = nil
11    for x = 1, #list do
12        temp2 = list[x]
13        if (temp2.className == "Model") and (temp2 ~= script.Parent) then
14            temp = temp2:findFirstChild("HumanoidRootPart")
15            human = temp2:findFirstChild("Humanoid")
View all 37 lines...

local dist = 45 --Change the number to the amount of studs the player has to be for the enemy to start chasing!

I'm assuming the enemy humanoid is named (Zombie) If it isn't go to line 34 and cahge Zombie to whatever the humanoid name is.

Hope this helps!

Ad