Hi! I am currently experiencing an odd issue for me regarding for loops, lerps, and Cframes.
Here is the code including the problem:
local camera = workspace.CurrentCamera
local player = game:GetService(“Players”).LocalPlayer
local char = player.Character or player.CharacterAdded:wait()
local runService = game:GetService(“RunService”)
local uis = game:GetService(“UserInputService”)
local humanoid = char:FindFirstChild(“Humanoid”)
runService.RenderStepped:Connect(function()
if humanoid then
if uis:IsKeyDown(Enum.KeyCode.Q) then
local pos = camera.CFrame* CFrame.Angles(0,0,math.rad(-2))
for i = 0,1,.01 do
local lerp = camera.CFrame:Lerp(pos,i)
camera.CFrame = lerp
wait() -- the problem
end
end
end
end)
__
My main goal was to tilt the camera influenced by the players walk direction.
Without “wait()”, it will tilt the camera but it would not be smooth. But when wait() is added inside the for loop, it would glitch instead and not tilt (The camera would lock its position for a few seconds until for i is done).