Trying to tween camera to part

local Camera = game.Workspace.Camera
local CamPart = workspace.Shop:FindFirstChild("Cam")-- Change ("here") to the camera that u want to
local TweenService = game:GetService("TweenService")

local TIME_TO_TWEEN = 0.5

local proximityPrompt = script.Parent

proximityPrompt.Triggered:Connect(function(player)
	local hum = player.Character:FindFirstChildOfClass("Humanoid")
	if Camera.CameraSubject and Camera.CameraSubject ~= CamPart then
		TweenService:Create(TIME_TO_TWEEN, TweenInfo.new(Enum.EasingStyle.Linear, Enum.EasingDirection.Out),{Camera=CamPart}):Play()
	else return Camera.CameraSubject==hum end
end)

Hi

I am trying to tween the current camera to the camera part. Any solutions? :slight_smile:

Also it’s an server side script

no errors btw ( edit )

local Camera = game.Workspace.Camera -- Get the camera from workspace
local CamPart = workspace.Shop:FindFirstChild("Cam") -- Get the camera part
local TweenService = game:GetService("TweenService") -- Get tween services

local TIME_TO_TWEEN = 0.5 -- Constant for tweening time

local proximityPrompt = script.Parent

proximityPrompt.Triggered:Connect(function(player)
	local hum = player.Character:FindFirstChildOfClass("Humanoid")
	if Camera.CameraSubject and Camera.CameraSubject ~= CamPart then
		local tween = TweenService:Create(
			Camera, -- The instance we are tweening
			TweenInfo.new(TIME_TO_TWEEN, Enum.EasingStyle.Linear, Enum.EasingDirection.Out),
			{CFrame = CamPart.CFrame} -- The property we are tweening, in this case the CFrame
		)
		tween:Play() -- play it
		tween.Completed:Wait() -- wait until its finished
		
		Camera.CameraSubject = CamPart -- so the check validates next time
	else 
		return Camera.CameraSubject == hum 
	end
end)

Hope I explained decently in comments
I would suggest reading the Documents for tweenservice,it could help a lot:

1 Like

uhh, still doesn’t work
does it need to be in a local script?

Yes.

aoskdlkfldskg character limit

still not working. The camera type it’s scriptable, the script it’s in the prompt, maybe I missed something

same

Okay let me setup a new script, put this one in StarterPlayerScripts. If you put it in the proxiimity prompt, local scripts dont/cant run unless they’re in specific stuff

local Player = game:GetService("Players").LocalPlayer

local Camera = game.Workspace.Camera -- Get the camera from workspace
local CamPart = workspace.Shop:FindFirstChild("Cam") -- Get the camera part
local TweenService = game:GetService("TweenService") -- Get tween services

local TIME_TO_TWEEN = 0.5 -- Constant for tweening time

local proximityPrompt = workspace:WaitForChild("Proximity") -- Change this with the path to your proximity prompt

proximityPrompt.Triggered:Connect(function()
	local hum = player.Character:FindFirstChildOfClass("Humanoid")
	if Camera.CameraSubject and Camera.CameraSubject ~= CamPart then
		
		Camera.CameraType = Enum.CameraType.Scriptable
		local tween = TweenService:Create(
			Camera, -- The instance we are tweening
			TweenInfo.new(TIME_TO_TWEEN, Enum.EasingStyle.Linear, Enum.EasingDirection.Out),
			{CFrame = CamPart.CFrame} -- The property we are tweening, in this case the CFrame
		)
		tween:Play() -- play it
		tween.Completed:Wait() -- wait until its finished
		
		Camera.CameraSubject = CamPart -- so the check validates next time
		
	else 
		return Camera.CameraSubject == hum
	end
end)

working, but if I press again the cam remains still

Sorry, this should fix that:

local Player = game:GetService("Players").LocalPlayer

local Camera = game.Workspace.Camera -- Get the camera from workspace
local CamPart = workspace.Shop:FindFirstChild("Cam") -- Get the camera part
local TweenService = game:GetService("TweenService") -- Get tween services

local TIME_TO_TWEEN = 0.5 -- Constant for tweening time

local proximityPrompt = workspace:WaitForChild("Proximity") -- Change this with the path to your proximity prompt

proximityPrompt.Triggered:Connect(function()
	local hum = Player.Character:FindFirstChildOfClass("Humanoid")
	if Camera.CameraSubject and Camera.CameraSubject ~= CamPart then

		Camera.CameraType = Enum.CameraType.Scriptable
		local tween = TweenService:Create(
			Camera, -- The instance we are tweening
			TweenInfo.new(TIME_TO_TWEEN, Enum.EasingStyle.Linear, Enum.EasingDirection.Out),
			{CFrame = CamPart.CFrame} -- The property we are tweening, in this case the CFrame
		)
		tween:Play() -- play it
		tween.Completed:Wait() -- wait until its finished

		Camera.CameraSubject = CamPart -- so the check validates next time

	else 
		Camera.CameraSubject = hum
	end
end)

Still tho, no errors, it’s just not working

Workspace.Camera can’t work in script.
It is server script and workspace.Camera returns the camera of the server.
So you need to make it again in local script.
Don’t copy and paste the script to local script. local scripts and scripts have lots of things different.

  • it should be workspace.CurrentCamera

same, but the return doesn’t work, practically it must get the camera to the humanoid

Try using WaitForChild instead of FindFirstChild.

Samee I tried em all, also there’s kinda no need for waitforchild

local Player = game:GetService("Players").LocalPlayer

local Camera = game.Workspace.Camera -- Get the camera from workspace
local CamPart = workspace.Shop:FindFirstChild("Cam") -- Get the camera part
local TweenService = game:GetService("TweenService") -- Get tween services

local TIME_TO_TWEEN = 0.5 -- Constant for tweening time

local proximityPrompt = workspace:WaitForChild("Proximity") -- Change this with the path to your proximity prompt

proximityPrompt.Triggered:Connect(function()
	local hum = Player.Character:FindFirstChildOfClass("Humanoid")
	if Camera.CameraSubject and Camera.CameraSubject ~= CamPart then

		Camera.CameraType = Enum.CameraType.Scriptable
		local tween = TweenService:Create(
			Camera, -- The instance we are tweening
			TweenInfo.new(TIME_TO_TWEEN, Enum.EasingStyle.Linear, Enum.EasingDirection.Out),
			{CFrame = CamPart.CFrame} -- The property we are tweening, in this case the CFrame
		)
		tween:Play() -- play it
		tween.Completed:Wait() -- wait until its finished

		Camera.CameraSubject = CamPart -- so the check validates next time

	else 
        Camera.CameraSubject = hum
        Camera.CFrame = Player.Character.PrimaryPart.CFrame
        Camera.CameraType = Enum.CameraType.Custom
	end
end)
1 Like

Can it also be tweened? I mean it’s cool

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