[SOLVED] Npc keeps teleporting back into the middle

This works, but with a problem. It’s trying to go to the Exit of the room at the same time, and I don’t know why.
Edit: Nevermind, i think i left something in there by accident.

Sadly it doesn’t work. as soon as he spawns, it causes intense lag, and then he despawns as if he made it.

Huh? You just told it worked…

Try this…
WalkingTest3.rbxl (159.3 KB)

function WalkToLocation(npc, dstCFrame)
	if dstCFrame and npc then
		local humanoid = npc:WaitForChild("Humanoid")
		humanoid:MoveTo(dstCFrame.Position)
		local timer = ((npc.PrimaryPart.Position - dstCFrame.Position).Magnitude/ humanoid.WalkSpeed)+2
		while timer > 0 do
			if ((npc.PrimaryPart.Position * Vector3.new(1,0,1)) - (dstCFrame.Position *Vector3.new(1,0,1)) ).Magnitude < 2 then
				break
			end
			timer = timer - task.wait()
		end
		npc.PrimaryPart:PivotTo(dstCFrame) 
	end
end

function TweenToLocation(npc,dstCFrame)
	local humanoid = npc:WaitForChild("Humanoid")
	local duration = ((npc.PrimaryPart.Position - dstCFrame.Position).Magnitude/ humanoid.WalkSpeed)
	local tweenInfo = TweenInfo.new(
		duration,
		Enum.EasingStyle.Quart,
		Enum.EasingDirection.Out,
		0,
		false,
		0
	)
	local tweenWalk = game.TweenService:Create(npc.PrimaryPart,tweenInfo,{CFrame = dstCFrame})
	tweenWalk:Play()
	tweenWalk.Completed:Wait()
end

function TweenRotation(npc,degrees,duration)
	local dstCFrame = npc.PrimaryPart.CFrame*CFrame.Angles(0,math.rad(degrees),0)
	local tweenInfo = TweenInfo.new(
		duration,
		Enum.EasingStyle.Quart,
		Enum.EasingDirection.Out,
		0,
		false,
		0
	)
	local tweenRotate = game.TweenService:Create(npc.PrimaryPart,tweenInfo,{CFrame = dstCFrame})
	tweenRotate:Play()
	tweenRotate.Completed:Wait()
end

task.wait(2)
local room = workspace.Rooms:FindFirstChild(game.ReplicatedStorage.CurrentRoom.Value)
if room then
	npc = script.Parent
	TweenToLocation(npc,room.Door.A60Stop.CFrame)
	TweenRotation(npc,-90,1)
	task.wait(2)
	WalkToLocation(npc,room.Door.DoorPart.CFrame)
	npc:Destroy()
end

but then i changed it
(character limit)))))))))

Hallelujah! This is pretty much what I needed, thanks!!

Oh shoot, I just realized it has to be a loop because the “room” Variable constantly changes, and he’s also being cloned.

Alright I figured it out
(CHARACTER LIMIT AAAAA)

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