RenderStepped (setting part's CFrame) causes very high lag

Still not solved. Anyone got any possible solutions?

What kind of method does the flashlight use for its light?

local info = TweenInfo.new(FlashlightModule.TweenSpeed, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false)
	
	local LightPart = nil
	local OnSound = nil
	
	if UV then
		LightPart = script:WaitForChild("UVPart"):Clone()
		
		OnSound = workspace:FindFirstChild("SFX"):FindFirstChild("IdleSoundUV"):Clone()
		OnSound.Parent = obj
		OnSound:Play()
	else
		LightPart = script:WaitForChild("LightPart"):Clone()
		
		OnSound = Instance.new("Sound")
		OnSound.Parent = obj
		OnSound.Name = "OnSound"
		OnSound.SoundId = "rbxassetid://198914875"
		OnSound:Play()
	end
	
	local Ring = LightPart:WaitForChild("Ring")
	local Light = LightPart:WaitForChild("Light")
	
	workspace.CurrentCamera:GetPropertyChangedSignal("CameraType"):Connect(function()
		if workspace.CurrentCamera.CameraType == Enum.CameraType.Custom then
			Light.Enabled = true
		else
			Light.Enabled = false
		end
	end)
	
	--LightPart.Anchored = true
	LightPart.Parent = workspace.CurrentCamera
	LightPart.CFrame = Camera.CFrame - obj.CFrame.LookVector -- Vector3.new(0,50,0)
	
	Light.Enabled = true
	Ring.Transparency = 0.747
	
	if mobile then
		Light.Brightness *= 2
	end
	
	if workspace.CurrentCamera.CameraType == Enum.CameraType.Custom then
		Light.Enabled = true
	else
		Light.Enabled = false
	end
	
	delay(1, function()
		OnSound:Destroy()
	end)
	
	
	connect = game["Run Service"].Heartbeat:Connect(function(DT)
		if LightPart then
			if not FlashlightModule.Lerp then
				game:GetService("TweenService"):Create(LightPart, info, {CFrame = Camera.CFrame - obj.CFrame.LookVector}):Play()
			else
				--LightPart.CFrame = LightPart.CFrame:Lerp(Camera.CFrame - obj.CFrame.LookVector, FlashlightModule.LerpSpeed)
			end
		end
	end)

You could try running the :Heartbeat() (which is now replaced by :PostSimulation()) code whenever the camera CFrame changes:

workspace.CurrentCamera:GetPropertyChangedSignal("CFrame"):Connect(function()
	if LightPart then
		if not FlashlightModule.Lerp then
			game:GetService("TweenService"):Create(LightPart, info, {CFrame = Camera.CFrame - obj.CFrame.LookVector}):Play()
		else
			--LightPart.CFrame = LightPart.CFrame:Lerp(Camera.CFrame - obj.CFrame.LookVector, FlashlightModule.LerpSpeed)
		end
	end
end)

Tried .Stepped, .RenderStepped, .Heartbeat and eve GetPropertyChangedSignal. Hasn’t fixed.

could it be the FlashlightModule then?

It’s not only the flashlight. There’s a trap tool that when equipped, sets a placeholder trap infront. Which also decreases FPS greatly. Anything that sets CFrame at a high speed just drops the FPS somehow. Haven never encountered this issue except now.

have you used RayCast before using it for your flashlight and trap?

Is this being run every time the flashlight is activated? If so, it could be that you aren’t disconnecting the RunService connections before setting a new one.

For example, the following does not disconnect the first Heartbeat connection.

connection = RunService.Heartbeat:Connect(function() end)
connection = RunService.RenderStepped:Connect(function() end)

You have to disconnect before connecting another function.

connection = RunService.Heartbeat:Connect(function() end)
connection:Disconnect()
connection = RunService.RenderStepped:Connect(function() end)

Yes I have, I know how it works.

Yes once it’s deactivated it gets :Disconnect(), this isn’t the issue even. The issue occurs meanwhile the loop, not after it.

If your using scripts with runcontext set to client it may be the issue.

I had a very simple tweening script that for some reason had more resource consumption than the other scripts (including one that set the cframe for a model every frame)

Soo how would I fix that exactly?
Edit: Ohhh nvm you were talking about the script’s property. But my scripts are LocalScripts, which don’t have RunContext as a property. So how would I go about fixing that?

are you sure this happens also in the normal roblox client? i have experienced a lot of weird fps drop from time to time, like when i equip tools in microsoft store roblox my fps just drops to 5~.

then maybe try this in an empty place it would help to know if its an hardware issue or not.

It’s happening on PC for everyone, haven’t tried Microsoft Roblox nor other devices yet.