Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How i can make that the NPC changes his speed when he is following you?

i have a little problem, How i can do that when the NPC are following you, its speed changes?

Here is the script

function findNearestTorso(pos)  --  declare pos a local vector3
	local list = game.Workspace:children()
	local torso = nil
	local dist = 25  -- Area to search
	local temp = nil
	local human = nil
	local temp2 = nil
	for x = 1, #list do
		temp2 = list[x]
		if temp2.className == "Model" then
			temp = temp2:findFirstChild("Torso")
			if temp ~= nil then
				human = temp2:findFirstChild("Humanoid")
				if human ~= nil and (human.Health > 0) and (temp2.Name ~= AIName) then -- not named the same as us.
					if (temp.Position - pos).magnitude < dist then
						torso = temp
						dist = (temp.Position - pos).magnitude
					end  --  closer?
				end   --  human? Not us. 
			end -- Has torso?
		end   --  Model? 
	end  --  For. Loop thru parts in Workplace

	return torso
end  -- findNearest

1 comment

1

Change the humanoids walkspeed?

1 answer

I don't seem to find the line that makes the NPC follow the player, but, when it does so you can do like this:

local NPC = script.Parent --Assuming that the script is in the NPC's character.
NPC:WaitForChild("Humanoid").WalkSpeed = [WALK SPEED NUMBER HERE]
else --If not find a torso
NPC:WaitForChild("Humanoid").WalkSpeed = [NORMAL WALK SPEED NUMBER HERE]

2 comments

0

You can put the "normal walk speed" on line 2 (in the original script) and the higher walk speed after "torso = temp"

0

That works too..

This discussion is preserved as it was. New answers, comments, and votes are closed.