Lag on crosshair

Hello.

This is my third post on the Scripting Support section, but I’ve been getting very busy on Roblox Studio today, and another problem has arisen!

I’m making a “fake” crosshair for a firearm I’m making. You can find a gif of it in action below.

The crosshair you see above, is not an ImageLabel, it is, in fact, two frames, their position being constantly updated in a loop. You can’t tell it on the gif because it has a low frame rate, however, in 60 frames per second, the crosshair is decently laggy. I have brought down the wait() to 0.00005, however still very choppy. At the moment, the way I’m having it move to the cursor is with UDim2.new(0,cursor.X,0,cursor.Y). I’m defining cursor as game.Players.LocalPlayer:GetMouse().

I can’t think of any other strategy to fix the lag of the crosshair. This is my first time doing anything like this, so any suggestions are always helpful.

I believe you should just use an input changed event as well this event fires every time the mouse position changes on screen.

Maybe also consider using the render step as it executes the script before anything else renders making it snappy.

Thanks for your comment. I’m not familiar with using any of the things you’ve just suggested, unfortunately. Can you give me an example of what code I should be implementing to my script to fix the issues I am having?

God bless.

Hmm, yeah it’s a bit complex since I just listed the possible solutions. For now just try to use renderstep and see how it goes

--Insert your code used to update crosshair it
local function updateCrosshair()

--[[Put your udim and mouse getting info here
UDim2.new(0,cursor.X,0,cursor.Y)
game.Players.LocalPlayer:GetMouse().
]]

end

--connect it to renderstep
RunService.RenderStepped:Connect(updateCrosshair)
1 Like

Thanks for your reply. I’m using a remote to manipulate an “asynchronous function” so my main script can continue.

And, after tweaking it to make it work with the way I prefer to layout my code, it has worked successfully. I deeply thank you for assisting me! God bless and have a good day/night.