How do I create an NPC that copies the player's movements but delayed

I’m trying to create an NPC that does the exact same action the player has done, except it does it a few seconds after the player, the result being something like Doppel from Grace or the Bind Maze entity in Slap Battles. I’ve checked everywhere but I can’t find a solution that can help me.

Here is my current code:

while game["Run Service"].Heartbeat do
			if npc == nil then break end
			headpos = script.Parent:FindFirstChild("Head").Position
			humrppos = script.Parent:FindFirstChild("HumanoidRootPart").Position
			larmpos = script.Parent:FindFirstChild("Left Arm").Position
			llegpos = script.Parent:FindFirstChild("Left Leg").Position
			rarmpos = script.Parent:FindFirstChild("Right Arm").Position
			rlegpos = script.Parent:FindFirstChild("Right Leg").Position
			torsopos = script.Parent:FindFirstChild("Torso").Position
			heador = script.Parent:FindFirstChild("Head").Orientation
			humrpor = script.Parent:FindFirstChild("HumanoidRootPart").Orientation
			larmor = script.Parent:FindFirstChild("Left Arm").Orientation
			llegor = script.Parent:FindFirstChild("Left Leg").Orientation
			rarmor = script.Parent:FindFirstChild("Right Arm").Orientation
			rlegor = script.Parent:FindFirstChild("Right Leg").Orientation
			torsoor = script.Parent:FindFirstChild("Torso").Orientation
			delay(1,function()
				npc:FindFirstChild("Head").Position = headpos
				npc:FindFirstChild("HumanoidRootPart").Position = humrppos
				npc:FindFirstChild("Left Arm").Position = larmpos
				npc:FindFirstChild("Left Leg").Position = llegpos
				npc:FindFirstChild("Right Arm").Position = rarmpos
				npc:FindFirstChild("Right Leg").Position = rlegpos
				npc:FindFirstChild("Torso").Position = torsopos
				npc:FindFirstChild("Head").Orientation = heador
				npc:FindFirstChild("HumanoidRootPart").Orientation = humrpor
				npc:FindFirstChild("Left Arm").Orientation = larmor
				npc:FindFirstChild("Left Leg").Orientation = llegor
				npc:FindFirstChild("Right Arm").Orientation = rarmor
				npc:FindFirstChild("Right Leg").Orientation = rlegor
				npc:FindFirstChild("Torso").Orientation = torsoor
			end)
			wait()
		end

Currently, the NPC just keeps teleporting to the player, and it does copy the movements, but I can’t seem to make it delayed.

3 Likes

i dont understand, from your script, its making the npc teleport to the player and copy its orientation

yeah, that’s whats happening, do you know how to fix it?

welp do you want the npc not to teleport to the player or no? or do you just want to make it follow behind?

it doesn’t really matter, as long as the npc has the effect of following the player as if it were copying their movements

Why not have the player periodically place a 0.1x0.1x0.1 transparent uncollidable “Breadcrumb” whose position the NPC :MovesTo()? The breadcrumbs can self-destruct after ~5 seconds

can you show me a code of what that would look like? im still pretty trash at scripting and my brain is fried after trying to figure this out for 2 hours.

The solution to trash scripting isn’t frying your brain on a problem you’re too inexperienced for
You should be reading the documentation or at least watching a scripting course (theres free ones on youtube)
If you can’t even use Humanoid:MoveTo() or create an Instance.new(“Part”) then I’m sorry the game you’re making is too difficult for your level of inexperience
Maybe you should look online for the two things I mentioned above and try making it yourself

P.S: Using the above would have retrace the player’s steps (think of those line-following robots) and may not exactly replicate the player’s motion to a T 100% of the time

I know how to use those but the problem is I want the NPC to copy the exact movements, I have done that but I want the movements to be delayed

Your current system is inefficient and hella overcomplicated
Try and get the NPC to follow the player’s path, it should create a good enough illusion
What I’ve told you WILL make the NPCs movements delayed

or you can just do this

npc:FindFirstChild("HumanoidRootPart").Position = humrppos+vecter3.new(0,0,-5)
while game["Run Service"].Heartbeat do
			local part = Instance.new('Part')
			part.Size = Vector3.new(0.1,0.1,0.1)
			part.Position = script.Parent.HumanoidRootPart.Position
			if npc == nil then break end
			npc.Humanoid:MoveTo(part.Position)
			wait(5)
			part:Destroy()
			wait()
		end

this is what i’ve got, but the npc gets stuck on some bits

i want the npc to at some point catch up to the player, as i want it to kill them

your making a monster? dang then this just got more complicated

1 Like

What if you increase the speed of the NPC every time it reaches a brick? Also, how about the bricks spawn more frequently every time as well? (You’ll have to ditch the heartbeat for this) This way the breadcrumb is closer and closer to the player, and by proxy, so is the Monster

1 Like

so how do i make the bricks spawn more frequently?

I’ll send you a script (since you have the concept down)

This script is inside the player’s character right?

1 Like

yeah, its a localscript inside startcharacterscripts

wait, i’ll try to put the wait and destroy under a spawned function to spawn much more crumbs