NPC teleporting to random parts

Hey guys!

I’ve been trying to get this to work and I’ve tried many times, for example :MoveTo, :PivotTo, setting the position or cframe to the position or cframe to the parts and it just won’t work.

local function spawnShadow()
	local randomPart = shadowFolder:GetChildren()[math.random(1, #shadowFolder:GetChildren())]
	local clone = shadow:Clone()
	clone.Parent = workspace
	clone.Position = randomPart.Position

	local prompt = Instance.new("ProximityPrompt")
	prompt.Parent = clone.UpperTorso
	prompt.ObjectText = "Destroy Shadow"
	prompt.RequiresLineOfSight = false
	prompt.HoldDuration = 2
	prompt.Triggered:Connect(function()
		clone:Destroy()
		clonesSpawned = clonesSpawned - 1
	end)

	clonesSpawned = clonesSpawned + 1
end

So, basically I’m trying to copy a monster to a random position but for some reason it just doesn’t want to teleport the monster. I’ve tried with a regular part and it works perfectly fine, so I’m thinking I’ve rigged it wrong.

I’ve tried HumandRootPart cframe and position, won’t work either.
I would appreciate some help!

Try switching it so it puts the Position first, then parents it to workspace.

And why not have the clone already in the shadowFolder with the ProximityPrompt already loaded in it? That way you don’t have to take time to create and set up the Prompt. Yes, it takes a tiny tiny amount of time, but any savings duing processing can benefit your game.

If that doesn’t help try printing the Position of the randomPart after it’s chosen from the folder to make sure you’ve actually got a destination to teleport to.

I’ve tried what you have said, but it says Position is not a valid member of monster. The Position of the randomPart works fine.

Maybe try this solved post:
Teleport a npc doesnt work

2 Likes

Edit - The solution to the link that Scottify sent above.

Is the monster a model? If so, you could use - clone:PivotTo( CFrame.new(randomPart.Position))

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.