Script works in studio but lags in game

Basically I have an ImageLabel following the player’s mouse. It’s an image containing hitmarker lines for the player’s crosshair, and I want it to look like it’s part of the crosshair since I can’t use two images at the same time for the player’s mouse icon.

My script works perfectly, but for some reason only in studio. In game, the ImageLabel just lags behind the crosshair.

Script:

local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")

local CrosshairHitmarker = script.Parent:WaitForChild("CrosshairHitmarker") -- This is the ImageLabel

RunService.RenderStepped:Connect(function()
	local MouseLocation = UserInputService:GetMouseLocation()
	CrosshairHitmarker.Position = UDim2.new(0, MouseLocation.X, 0, MouseLocation.Y)
end)

In studio (which is how it’s supposed to look like):

In game:

I’ve already tried using Mouse.Moved, RunService:BindToRenderStep(), RunService.Stepped, RunService.Heartbeat, limiting my fps, changing my mouse’s polling rate, etc., but nothing works. It also apparently works for my friend, but not me.

It might be because the because the camera updates before the Image label, so try using BindToRenderedStep()

local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")

local CrosshairHitmarker = script.Parent:WaitForChild("CrosshairHitmarker") -- This is the ImageLabel

RunService:BindToRenderedStep("before camera", Enum.RenderPriority.Camera.Value - 1)
	local MouseLocation = UserInputService:GetMouseLocation()
	CrosshairHitmarker.Position = UDim2.new(0, MouseLocation.X, 0, MouseLocation.Y)
end)

--i didnt test this so theres a chance the syntax is wrong

Unfortunately didn’t work. I just decided to not change the mouse icon, and instead use an image label for the crosshair itself. Then I’d just set the crosshair and crosshair hitmarker positions to the same position every render step. Guns are still accurate so it might be a visual bug

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.