In my game, some of the animations rely on CFrame lerps in the Renderstepped function below. As well as this, the automatic fire system uses a while do function. The problem is, both of these functions run faster with an FpS unlocker. How can I lock these functions to 60 FpS?
RenderStep function
Run.RenderStepped:Connect(function(deltaTime)
if dead.Value == false and gun.weapon then
local mouseDelta = game:GetService("UserInputService"):GetMouseDelta()
mouse.TargetFilter = cam
DT = deltaTime
if switching then
gun.switchCF = gun.switchCF:Lerp(gun.module.switchcf, .1)
elseif switching == false then
gun.switchCF = gun.switchCF:Lerp(CFrame.new(), .1)
end
if gun.weapon then
gun.weapon:SetPrimaryPartCFrame(cam.CFrame
* CFrame.new(gun.module.regularcf.Position.X,-1.7,gun.module.regularcf.Position.Z)
* gun.switchCF
* gunbobcf
* aimcf
* sprintcf
* recoilcf
)
end
-- [[ States ]] --
if (gun.state == gun.states.idle) then
gun.mainCF = gun.mainCF:lerp(CFrame.new(gun.module.regularcf.Position.X,-1.7,gun.module.regularcf.Position.Z),.3)
if not gun.animationTrack.idle.IsPlaying then
gun.animationTrack.idle:Play()
end
end
if running then
gunbobcf = gunbobcf:Lerp(CFrame.new(
0.14 * math.sin(tick() * 6), -- Intensity left/right * speed
0.07 * math.sin(tick() * 12), -- Intensity up/down * speed
-0.005 * math.sin(tick() * 1) -- Intensity back/forward * speed
), 0.1)
--[[
elseif running and aiming then
gunbobcf = gunbobcf:Lerp(CFrame.new(
0.04 * math.sin(tick() * 1), -- intensity left/right * math.sin(tick() * speed
0.02 * math.sin(tick() * 2), -- intensity up/down * math.sin(tick() * speed
-0.025 * math.sin(tick() * 1)
), 0.1)
--]]
elseif sprinting then
gunbobcf = gunbobcf:Lerp(CFrame.new(
0.14 * math.sin(tick() * 6), -- intensity left/right * math.sin(tick() * speed
0.07 * math.sin(tick() * 6), -- intensity up/down * math.sin(tick() * speed
-0.3 * math.sin(tick() * 6)
), 0.1)
else
gunbobcf = gunbobcf:Lerp(CFrame.new(),0.1)
end
if sprinting then
-- print('is sprihnting')
local tween = Tween:Create(cam, aimTween, {FieldOfView = 55/1.4}) --fov+zoom
tween:Play()
gun.mainCF = gun.mainCF:Lerp(CFrame.new(gun.module.regularcf.Position.X,-1.7,gun.module.regularcf.Position.Z) * CFrame.Angles(-.75,1,0.25),.1)
if char.Humanoid.WalkSpeed > .1 then
gunbobcf = gunbobcf:Lerp(CFrame.new(
0.14 * math.sin(tick() * 1), -- intensity left/right * math.sin(tick() * speed
0.07 * math.sin(tick() * 2), -- intensity up/down * math.sin(tick() * speed
-0.7 * math.sin(tick() * 8)
), 0.1)
end
else
local tween = Tween:Create(cam, aimTween, {FieldOfView = 55}) --fov
tween:Play()
gun.mainCF = gun.mainCF:Lerp(CFrame.new(),.1)
end
--[[
if aiming then
local tween = Tween:Create(cam, aimTween, {FieldOfView = 70/gun.module.Zoom}) --fov+zoom
tween:Play()
aimcf = aimcf:Lerp(gun.module.aimcf, 0.1) -- goal cframe (lower number, lower aimspeed)
else
local tween = Tween:Create(cam, aimTween, {FieldOfView = 70}) --fov
tween:Play()
aimcf = aimcf:Lerp(CFrame.new(), 0.1)
end
if crouching then
char.Humanoid.CameraOffset = Vector3.new(0,-4,0)
else
char.Humanoid.CameraOffset = Vector3.new(0,0,0)
end
--]]
gun.springs.inputSway:shove(Vector3.new(mouseDelta.x / 200 , mouseDelta.y / 200)) --not sure if this needs deltaTime filtering
local sway = gun.springs.inputSway:update(deltaTime)
gun.weapon.Primary.CFrame = gun.weapon.Primary.CFrame * CFrame.Angles(0,-sway.x,-sway.y)
recoilcf = recoilcf:Lerp(CFrame.new(), 0.1)
end
end)
While do function
mouse.Button1Down:Connect(function()
mouseldown = true
sprinting = false
Events.Sprint:FireServer(gun.module.GunWalkSpeed)
delay(0, function()
if gun.module.ShootType == 2 and reloading == false and gun.module.Ammo > 0 then
if gun.module.Ammo > 0 or gun.module.Ammo == 1 then
while mouseldown and not sprinting do
if shooting or sprinting or switching then
Events.Sprint:FireServer(gun.module.GunWalkSpeed)
break
end
if gun.module.Ammo > 0 or gun.module.Ammo == 1 then
if reloading == false then
if gun.module.WeaponType == "Gun" then
gun.module.Ammo = gun.module.Ammo - 1
PlrGui.GunInfo.Frame.Ammo.Text = gun.module.Ammo
PlrGui.GunInfo.Frame.Reserve.Text = gun.module.Reserve
ShootRecoil()
newBullet()
shooting = false
end
end
end
end