1. What do you want to achieve?
I want to move the camera to CameraTarget1
when a player clicks a button. The camera should stay at CameraTarget1
without returning to the initial position (CameraTarget
) after the tween completes.
2. What is the issue?
When I press the button to move the camera to CameraTarget1
, the camera moves smoothly to the target but then immediately returns to the initial position (CameraTarget
). This happens despite only trying to set the camera to CameraTarget1
once the button is clicked.
3. What solutions have you tried so far?
- I have tried setting
camera.CFrame
directly toCameraTarget1
and also used a tween to move the camera, but the camera still returns toCameraTarget
after the tween ends. - I have also tried using different
TweenInfo
configurations and checked for any conflicting code.
blurEffect.Size = 6
blurEffect.Enabled = true
local Part = workspace:WaitForChild("CameraTarget")
local goalCFrame = Part.CFrame
camera.CameraType = Enum.CameraType.Scriptable
local tweenInfo = TweenInfo.new(1)
local tween = TweenService:Create(camera, tweenInfo, {CFrame = goalCFrame})
tween:Play()
tween.Completed:Connect(function()
local offset = CFrame.new(0, 3, -10)
local maxAngle = 10
local smoothSpeed = 0.1
RunService:BindToRenderStep("LimitedMouseLook", Enum.RenderPriority.Camera.Value + 1, function()
local viewSize = camera.ViewportSize
local xNorm = (mouse.X / viewSize.X - 0.5) * 2
local yNorm = (mouse.Y / viewSize.Y - 0.5) * 2
xNorm = math.clamp(xNorm, -1, 1)
yNorm = math.clamp(yNorm, -1, 1)
local xRot = math.rad(-yNorm * maxAngle)
local yRot = math.rad(-xNorm * maxAngle)
local baseCFrame = Part.CFrame * offset
local targetCFrame = baseCFrame * CFrame.Angles(xRot, yRot, 0)
camera.CFrame = camera.CFrame:Lerp(targetCFrame, smoothSpeed)
end)
end)
local Target1 = workspace:WaitForChild("CameraTarget1")
local goalCFrame1 = Target1.CFrame
local tweenInfo1 = TweenInfo.new(1)
local tween1 = TweenService:Create(camera, tweenInfo1, {CFrame = goalCFrame1})
button.MouseButton1Click:Connect(function()
tween1:Play()
end)