Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do i change the position of the mouse cursor?

Asked by 5 years ago

Hello, i am making this gui that has a selector that changes it's rotation based on the mouse position (I did not make that script, the person i am working with made that.)

I am trying to script it so that the mouse position is at the middle of the screen.

This is my current script:

local mouse = plr:GetMouse()
InputService.InputBegan:Connect(function(key, chat)
    if chat then return end
    if key.KeyCode == Enum.KeyCode.T then
        mouse.X = 0
        mouse.Y = 0
    end
end)

However, whenever i test the script out the log says says that it can't set the value

I don't want the mouse locked in the middle, i just want the mouse to be moved to the middle of the screen, it is free to move after that.

Any help is appreciated, thanks.

1 answer

Log in to vote
0
Answered by 5 years ago

You can also do it like this..

function ReticleUpdate(mouse)
    MouseGUI.MouseUp.Position = UDim2.new(0, mouse.X-2, 0, mouse.Y-30-Recoil)
    MouseGUI.MouseDown.Position = UDim2.new(0, mouse.X-2, 0, mouse.Y+5+Recoil)
    MouseGUI.MouseLeft.Position = UDim2.new(0, mouse.X-30-Recoil, 0, mouse.Y-2)
    MouseGUI.MouseRight.Position = UDim2.new(0, mouse.X+5+Recoil, 0, mouse.Y-2)
    MouseGUI.Hit.Position = UDim2.new(0, mouse.X-32, 0, mouse.Y-32)
end

you can remove the +/- Recoil, just a bit of recoil for the gun MouseGUI is like the part in your GUI, which can be anything.

0
or you can do mouse.Move:connect(function() OnceLegend 3 — 5y
Ad

Answer this question