There are two kinds of methods, one with setTimer and the other with the alternative onClientRender
setTimer :
The cursor always appears in the center for one frame after showCursor(true).
function openPanel()
showCursor(true)
-- Save the last cursor position (values between 0 and 1)
local x, y = getCursorPosition()
-- Get the screen resolution
local sx, sy = guiGetScreenSize()
-- After 50ms, set the cursor back to its previous position
setTimer(function()
setCursorPosition(x * sx, y * sy)
end, 50, 1)
end
onClientRender:
Use a timer or onClientRender to set the position after showing the cursor.
function panelAc()
showCursor(true)
local x, y = getCursorPosition()
local sx, sy = guiGetScreenSize()
local function imlecDuzelt()
setCursorPosition(x * sx, y * sy)
removeEventHandler("onClientRender", root, imlecDuzelt)
end
addEventHandler("onClientRender", root, imlecDuzelt)
end
your fixed code :
local toggle = false
local savedCursorX, savedCursorY
local function togglePanel()
toggle = not toggle
if toggle then
showCursor(true)
if savedCursorX and savedCursorY then
local screenX, screenY = guiGetScreenSize()
-- Wait one frame before setting the cursor position
setTimer(function()
setCursorPosition(savedCursorX * screenX, savedCursorY * screenY)
end, 50, 1)
end
else
savedCursorX, savedCursorY = getCursorPosition()
showCursor(false)
end
end
bindKey("k", "down", togglePanel)
I think you understand, if you have a different problem please post it here or create a new topic and tag me