[Script Idea] Stuck UI fixer

I’ve spent a few days looking for something like this, and… well, safe to say I didnt find anything. Not even a hint at how a script would go about “fixing” stuck client-sided UI.
As an example, while using some inventoryhud + a radial menu, with some precise timing you can get both to open, but when closing the inventory the radial menu is stuck on your screen with you being unable to interact with it (yes, pressing the button to open it does nothing as well). There’s pretty much one way to fix the issue, and that’s to restart the resource to which the stuck UI belongs.
However, that may not always be possible, particularly on servers which employ the use of resource tokens (basically not allowing the client to have a difference in what resources are run on it when compared to the server every X seconds). That said, you can also relog, but that takes away a fair bit of time and it’s quite frustrating.
I saw a few natives related to UI that may be able to restart the UI itself client-side, but creating something like this is way, way out of my league.
So, if you’re an experienced developer (or just want to try your hand in a new resource and you have no ideas as to what to make), give the above a shot!
I’m sure the community will find such a release quite useful if shared publicly and freely - it’s not rare for UI elements to overlap and get stuck due to how most UI-containing resources handle it, and a way to fix it without relogging will be welcome.

1 Like

I did something pretty simple to solve this issue (which can probably be cleaned up a lot to look better)

local currentResource
local lineNumber

exports('CanUpdateNuiFocus', function(lineNumb, hasFocus)
	local resource = GetInvokingResource()
    -- check if its the same resource, else fail and return the fail.
    if not currentResource or currentResource == resource then
        if hasFocus then
			currentResource = resource
			lineNumber = lineNumb
        else
			currentResource = nil
			lineNumber = nil
        end
        return true
    elseif currentResource then
        print(('%s [line: %s] is currently holding focus! (%s was trying to take it)'):format(currentResource, lineNumber, resource))
        return false
    end
end)

General Usage would be like

if exports['resource-name']:CanUpdateNuiFocus(debug.getinfo(1).currentline, true) then
-- show ui
end

You have to remember to always give up focus afterwards, as if a Nui doesn’t give up focus, no other nui will be able to open.

RegisterNUICallback('closeUi', function(data)
    exports['resource-name']:CanUpdateNuiFocus(debug.getinfo(1).currentline, false) 
end)

There’s probably a better way to do this, but this works pretty well for us, but its still completely possible to get stuck in your Nui.

1 Like

I’d still imagine you can break it with some precise frame-perfect inputs, and that’s something that can happen even by accident. That’s a good share, though, but not exactly what I intended for people to look into :laughing:

Still possible with the right timing, yes, but in general it will fix most of the issues.

Just make a command that sets nui focus. Then you type that command in console and done all ui fixed

Or you could always set nui focus to false or off and then back on when opening inventory or radial menu to avoid stuck frames