local tool = script.Parent
tool.Equipped:Connect(function()
for i = .1,1,.1 do
workspace.Camera.CFrame = workspace.Camera.CFrame:Lerp(workspace.Camera.CFrame * CFrame.new(0,0,2), 0.05)
end
end)
That doesn’t tell me what the problem is still. Looking at your code I can see you’re using a for loop without any yielding. The code in the for loop is going to execute instantly.
If you want to Lerp the camera you need to use RunService.RenderStepped in a LocalScript. You can use RunService.RenderStepped:Wait() inside of the for loop and it will wait for one frame. Each frame the camera is rendered so that will sync the movement with each frame.
can i just insert RunService.RenderStepped:Wait() above the lerping code like this
local tool = script.Parent
local RunService = game:GetService("RunService")
tool.Equipped:Connect(function()
for i = .1,1,.1 do
RunService.RenderStepped:Wait(1)
workspace.Camera.CFrame = workspace.Camera.CFrame:Lerp(workspace.Camera.CFrame * CFrame.new(0,0,2), 0.05)
end
end)
local tool = script.Parent
local Camera = game.Workspace.Camera
tool.Equipped:Connect(function()
local Orig = workspace.Camera.CFrame
for i = 0,1,.1 do
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = Orig:Lerp(Orig * CFrame.new(0, 0, 20), i)
wait(0.01)
print(1)
end
end)
Event:Wait() doesn’t have any function arguments. It just waits for the event to fire. Event:Connect() calls a function every time the event fires. RenderStepped is an event on the service RunService which fires every frame.
You can insert it into the for loop and it will wait for one frame each iteration of the loop. The game runs at 60 fps normally so Lerping for 60 frames will Lerp for about one second.
Lerp’s second argument (delta) is like a percent. It takes the CFrame you give it in arguments (the target) and moves the CFrame before the : to the target CFrame. If delta is one the value Lerp returns will be the target. If delta is zero the value Lerp returns is the original CFrame.
So your delta should be i/maxi. So if your for loop goes from 1 to 60 and you wait a frame at the beginning your delta should be i/60. You can also put the 60 in a variable to make it easy to change. You can also use something like this to specify seconds to lerp: timeToLerp*60
local tool = script.Parent
local Camera = game.Workspace.CurrentCamera
tool.Equipped:Connect(function()
local Orig = workspace.CurrentCamera.CFrame
for i = 0,1,.1 do
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = Orig:Lerp(Orig * CFrame.new(0, 0, 2), i)
wait(0.01)
print(1)
end
end)
Thank you so much for your help!,i forgot to set Require Handle to false,since i was just testing