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

How Do I Make An NPC Dash To The Nearest Player? (Answered!)

I'm trying to make it so that a part goes to a player's torso's CFrame, but I'm not sure how to do this. I have a script that moves the part but I want it to move towards the nearest player's torso's CFrame. How would I do this? Please help.

Thank you!

local distance = 30

	script.Parent.Anchored = true

	for i = 0, distance do
		script.Parent.CFrame = script.Parent.CFrame + Vector3.new(0,0,0.2) -- Supposed to target nearest humanoid
		wait()
	script.Parent.Anchored = false
end

1 answer

Using the lookvector of the npc because the npc is facing the nearest player to attack it, I just put a most script into it's head, which makes it dash forwards.

(Dash script)

local distance = 30

	script.Parent.Anchored = true

	for i = 0, distance do
		script.Parent.CFrame = script.Parent.CFrame+(script.Parent.CFrame.LookVector*1.5)
		wait()
	script.Parent.Anchored = false
end

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