How do I stop the cameraoffset being reset to 0,0,0 every time a tween is completed?


local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local isTweening = false 

local UIS = game:GetService("UserInputService")
local tweenService = game:GetService("TweenService")
local ti = TweenInfo.new(
    0.5,
    Enum.EasingStyle.Cubic
)


UIS.InputBegan:Connect(function(key, isTyping)
    if isTweening==false then 
        if key.KeyCode == Enum.KeyCode.E then
            isTweening = true
            local t1 = tweenService:Create(humanoid, ti, { CameraOffset = Vector3.new(1.6, 1, 0) })
            t1:Play()
            t1.Completed:Connect(function()
                humanoid.CameraOffset = Vector3.new(1.6, 1, 0)
                isTweening = false 
            end)
        end
        if key.KeyCode == Enum.KeyCode.Q then
            isTweening = true
            local t1 = tweenService:Create(humanoid, ti, { CameraOffset = Vector3.new(-1.6, 1, 0) })
            t1:Play()
            t1.Completed:Connect(function()
                humanoid.CameraOffset = Vector3.new(-1.6, 1, 0) 
                isTweening = false 
            end)
        end
    end
end)

UIS.InputEnded:Connect(function(key)
    if key.KeyCode == Enum.KeyCode.E or key.KeyCode == Enum.KeyCode.Q and isTweening==true then
        isTweening = false 
        tweenService:Create(humanoid, ti, { CameraOffset = Vector3.new(0, 0, 0) }):Play()
    end
end)

Yeah so idk why the camera offset keeps on resetting after the tween completes even though I setted the camera offset manually after the tween completes

1 Like

I’ve also tried manually setting the camera offset after the tween completes but it still does not work?

1 Like

What’s the isTweening bool for, it doesn’t seem to be doing anything, did you mean to debounce the inputEnded and forgot?

oh yeah, lemme edit the script