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?
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:
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)
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)
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.
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)