I want to figure out how to give an NPC the ability to randomly glitch in and out during the course of it chasing a player. Like a ghost type effect where it disappears and reappears. The thing is that I only know how to make something teleport to a fixed location, but what I want is it to be following you and teleport say 2 or 3 steps forward. Is there any way to accomplish that?
✓ ANSWER ACCEPTED
Teleport Effect While NPC is Chasing?
1 answer
✓ Accepted answer
You can teleport the NPC forward by calculating the CFrame in front of it by a certain distance:
local function teleport(character, forwardDistance)
local rootPart = character:FindFirstChild("HumanoidRootPart")
if rootPart then
local destinationCFrame =
rootPart.CFrame:toWorldSpace(CFrame.new(0,0,-forwardDistance))
rootPart.CFrame = destinationCFrame
end
end
-- Every 2 seconds, teleport an NPC forward by 5 studs
local npc = game.Workspace.NonPlayerCharacter -- A character model
while wait(2) do
teleport(npc, 5)
end
Edit: For more information about how the CFrame calculation works, check out this Wiki page.
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
Thanks. I will try this when i log on
Worked Perfectly. Thanks