As you can see in the clip above, the Aiming CFrame gets faster and faster every time I equip the tool.
I have looked at many forum posts but couldn’t find anything about CFrames getting faster.
Code:
-- Viewmodel is a pair of arms in the camera
-- AimPart is where I want the viewmodel to go
-- AimSpeed is 0.1
RunService.RenderStepped:Connect(function(step)
if Aiming then
local AimOffset = Viewmodel.HumanoidRootPart.CFrame:ToObjectSpace(Viewmodel.Handle.AimPart.WorldCFrame):Inverse()
AimCF = AimCF:Lerp(AimOffset, AimSpeed)
else
local AimOffset = CFrame.new()
AimCF = AimCF:Lerp(AimOffset, AimSpeed)
end
end
I think this topic will be better to post under #help-and-feedback:scripting-support.
Also, the problem you may have is Lerping, bc it’s possible to set lerp more than 1 and less than 0.
Since i cant see the whole code, i assume that you put the RenderStepped event inside the Equipped event, which is causing the problem. Every time you equip a tool, it connects another function to the RenderStepped event. The more functions connected, the faster CFrame will change
for example:
you have equipped the tool 1 time, the function will be called 1 time per RenderStepped.
you have equipped the tool 2 times, the function will be called 2 times per RenderStepped.
if i guessed right and you put the RenderStepped event inside the Equipped event, to fix this issue you need to move the RenderStepped out of Equipped event or to disconnect the function from RenderStepped everytime you Unequip the tool by doing so:
local Connection = nil
Tool.Equipped:Connect(function()
Connection = RunService.RenderStepped:Connect(YourFunction)
-- rest of your code
end)
Tool.Unequipped:Connect(function()
Connection:Disconnect()
end)