I had to work on this topic for about two weeks and I want to save people’s time with this because no one else could solve the same problem as me. The problem surrounds that when I’m aiming in the mouse cursor is not centered and I implemented peoples code to my problem to no avail as it required me to move my mouse first to get it centered. Here is the code.
local screenCenter = Vector2.new(workspace.CurrentCamera.ViewportSize.X / 2, workspace.CurrentCamera.ViewportSize.Y / 2)
RunService:BindToRenderStep(“MouseLock”, Enum.RenderPriority.Last.Value + 1, function()
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
if UserInputService.MouseIconEnabled then
local mouseLocation = UserInputService:GetMouseLocation()
if mouseLocation ~= screenCenter then
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter -- Force again if moved
end
end
end)
I hope I made someones day