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

Why will this NPC teleport script not work? [FIXED]

So I am trying to make it so an NPC character will be constantly teleported in front of a player. This script should work as far as I'm aware. In a seperate script, a part is welded to the player, tpPart or PartToWeld, and the NPC should be constantly being teleported to the part. The script gives no errors and "did" is printed repeatedly. This script is a local script, I put it inside a local script so the player could only see their NPC and no one else's. Any ideas?

while true do
			wait()
			print("did")
			local player = game.Players.LocalPlayer
			local man = game.Workspace.NPC:Clone()
			local tpPart = player.Character.PartToWeld
			man:SetPrimaryPartCFrame(tpPart.CFrame * 			CFrame.fromEulerAnglesXYZ(math.rad(0), math.rad(180), math.rad(0)))
end

1 answer

I fixed it. There were two problems:

  1. I was cloning it every cycle so that's a problem of itself
  2. I forgot to parent the clone to Workspace

New code:

		local man = game.Workspace.NPC:Clone()
		man.Parent = game.Workspace
		while true do
			wait()
			local player = game.Players.LocalPlayer
			local tpPart = player.Character.PartToWeld
			man:SetPrimaryPartCFrame(tpPart.CFrame * 		CFrame.fromEulerAnglesXYZ(math.rad(0), math.rad(180), math.rad(0)))
		end

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