Camera Teleporting after executing a tween

After my script completes a tween to the camera it just teleports and i have no idea why.

  1. What do you want to achieve? I wan’t to fix that, but i have no idea how.

  2. What is the issue? The camera teleports after completing a tween.

  3. What solutions have you tried so far? I tried to search in YT, Devforum, but i found nothing to help and that’s why im creating this topic.

Im makin a hiding system for my horror game and i want it to be smooth. So i really wan’t to fix this.

movecamEvent.OnClientEvent:Connect(function(cframe, argument, cameraPlace)
	humanoid.CameraOffset = Vector3.new(0,0,0)
	
	if argument == "closet" then
		local currentCamera = workspace.CurrentCamera
		currentCamera.CameraType = Enum.CameraType.Scriptable
		local tween = tweenService:Create(currentCamera, TweenInfo.new(0.5), {CFrame = cframe})
		tween:Play()
		task.wait(0.5)
		currentCamera.CameraType = Enum.CameraType.Custom
		--
	elseif argument == "bed" then
		if cameraPlace == "inside" then
			animate:Fire(argument, "inside")
			local currentCamera = workspace.CurrentCamera
			currentCamera.CameraType = Enum.CameraType.Scriptable
			local tween = tweenService:Create(currentCamera, TweenInfo.new(0.5), {CFrame = cframe})
			tween:Play()
			task.wait(0.5)
			humanoid.CameraOffset = Vector3.new(0, -3.35, 0)
			currentCamera.CameraType = Enum.CameraType.Custom
		else
			humanoid.CameraOffset = Vector3.new(0,0,0)
			animate:Fire(argument, "outside")
			local currentCamera = workspace.CurrentCamera
			currentCamera.CameraType = Enum.CameraType.Scriptable
			local tween = tweenService:Create(currentCamera, TweenInfo.new(0.5), {CFrame = cframe})
			tween:Play()
			task.wait(0.5)
			currentCamera.CameraType = Enum.CameraType.Custom
		end
		end
end)

I also have this video to show.

It looks like the camera is teleporting because you are setting the CameraType to Enum.CameraType.Custom right after the tween completes. This causes the camera to snap to the player’s character’s head, which might appear as if it’s teleporting.

To fix this issue, you can try removing the currentCamera.CameraType = Enum.CameraType.Custom line or replacing it with currentCamera.CameraType = Enum.CameraType.Follow . This will allow the camera to smoothly follow the player’s character’s head position, rather than snapping to it.

Alternatively, you can also try using the Completed event of the tween object to set the CameraType to Enum.CameraType.Custom or Enum.CameraType.Follow once the tween has completed. This way, the camera’s type won’t be changed until the tween has finished, which should make the transition smoother.

Here’s an example of how you can use the Completed event.

local tween = tweenService:Create(currentCamera, TweenInfo.new(0.5), {CFrame = cframe})
tween.Completed:Connect(function()
  currentCamera.CameraType = Enum.CameraType.Follow
end)
tween:Play()

if it’s hard to understand I would do more in detail

                                               ⚠️ Warning ⚠️

I’m only trying to help

This code was made by AI

It looks like the camera is teleporting because you are setting the CameraType to Enum.CameraType.Custom right after the tween completes. This causes the camera to snap to the player’s character’s head, which might appear as if it’s teleporting.

The CameraType property determines how the camera should behave. There are several different camera types available, including Custom , Follow , Track , and Scriptable .

The Custom camera type allows you to specify the camera’s position and orientation directly, using the CFrame property of the Camera object. When the CameraType is set to Custom , the camera will snap to the position and orientation specified by the CFrame property, which can make the camera appear to teleport if the CFrame changes abruptly.

To fix this issue, you can try removing the currentCamera.CameraType = Enum.CameraType.Custom line or replacing it with currentCamera.CameraType = Enum.CameraType.Follow . This will allow the camera to smoothly follow the player’s character’s head position, rather than snapping to it.

Alternatively, you can also try using the Completed event of the tween object to set the CameraType to Enum.CameraType.Custom or Enum.CameraType.Follow once the tween has completed. This way, the camera’s type won’t be changed until the tween has finished, which should make the transition smoother.

Here’s an example of how you can use the Completed event.

local tween = tweenService:Create(currentCamera, TweenInfo.new(0.5), {CFrame = cframe})
tween.Completed:Connect(function()
  currentCamera.CameraType = Enum.CameraType.Follow
end)
tween:Play()

This code creates a new tween that animates the CFrame property of the currentCamera object over a period of 0.5 seconds. The Completed event is triggered when the tween finishes playing, and it sets the CameraType to Enum.CameraType.Follow . This will cause the camera to smoothly follow the player’s character’s head position, rather than snapping to it.

I hope this helps to explain the issue and how you can fix it. Let me know if you have any further questions!

Im gonna try to see if this helps! Currently im not using my PC so i’ll try it later. Thanks!

It works! Thank you so much! I never knew the Camera Type Follow could do this!

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