Interaction still flickering

Ok, so a week or so ago i posted on here about a problem i had with my interaction flicking on the side.

Well people suggested i should make it like this:

When in distance

						if not intShown then
							intShown = true
							TriggerEvent("okokTextUI:Open", "[E] "..displayText, closestColor, "left")
						end

When outside of distance

				if intShown then
					intShown = false
					TriggerEvent("okokTextUI:Close")
				end

But it is still flickering.

GIF of flicker:

My full code for the doorlocks (relvevant part):

Citizen.CreateThread(function()
    local intShown = false
    while true do
        local isLocked = false
        local doorDistance = 1000
		local closestColor = "None"
		Citizen.Wait(5)
		local playerCoords, awayFromDoors = GetEntityCoords(PlayerPedId()), true

		for i = 1, #PS.Doors do
			local current = PS.Doors[i]
            isLocked = current.locked
            doorDistance = #(current.objCoords - playerCoords)
			local distance

				distance = #(playerCoords - current.objCoords)

			if current.distance then
				maxDistance = current.distance
			end

			if distance < 10 then
				awayFromDoors = false
				if current.doors then
					for a = 1, #current.doors do
						local currentDoor = current.doors[a]
						FreezeEntityPosition(currentDoor.object, current.locked)

						if current.locked and currentDoor.objYaw and GetEntityRotation(currentDoor.object).z ~= currentDoor.objYaw then
							SetEntityRotation(currentDoor.object, 0.0, 0.0, currentDoor.objYaw, 2, true)
						end
					end
				else
					FreezeEntityPosition(current.object, current.locked)

					if current.locked and current.objYaw and GetEntityRotation(current.object).z ~= current.objYaw then
						SetEntityRotation(current.object, 0.0, 0.0, current.objYaw, 2, true)
					end
				end
			end

			if distance <= 1.0 then
				awayFromDoors = false
				if current.size then
					size = current.size
				end

				if current.locked then
					displayText = "Locked"
					closestColor = "darkred"
				elseif not current.locked then
					displayText = "Unlocked"
					closestColor = "darkgreen"
				end


						if not intShown then
							intShown = true
							TriggerEvent("okokTextUI:Open", "[E] "..displayText, closestColor, "left")
						end

				if current.objCoords == nil then
					current.objCoords = current.textCoords
				end


				if IsControlJustReleased(0, 38) then
						setDoorLocking(current, i)
				end
			elseif distance > 1.0 then
				if intShown then
					intShown = false
					TriggerEvent("okokTextUI:Close")
				end
			end
		end
    


		if awayFromDoors then
			Citizen.Wait(1000)
		end
	end
end)

What i’ve already tried:

Adding distance check and elseif’s inside the current if statement checking distance. Didn’t work.

Any help would be appreciated!

Could you do me a favor here and add a debug print inside here:
if not intShown then
print(‘rendering UI’)
intShown = true
TriggerEvent(“okokTextUI:Open”, "[E] "…displayText, closestColor, “left”)
end

This should only be executed once, because of the animation inside ur ui. Like I said before. It could also be that you are in range of multiple doors so everyone of them triggers an ui event. You have to make sure its only started once. So maybe you have to move the check outside of this plugin inside your ui plugin. This would be more reliable as it would prevent flickering even when multiple sources use it.

I have distance check for doors on 1.0 distance.

Just tried putting print, and it’s spamming the console.

Now we now for sure that the current implementation is not working as intended.

We have two options here. We either change the current code that calls the UI framework. Or we change the UI framework directly. I would recommend changing the UI directly because, like I said, we make sure it will never flickr again regardless of where you use it.

What you want to do is. Go into the UI implementation and implement this “is UI shown” check. Inside “okokTextUI:Open” add a boolean that turn true once the UI is visible and in “okokTextUI:Close” reset this value. And obviously only send a NUI message when UI is not show (in okokTextUI:Open)

Okay ill try it out.

Okay, so like this:

local intShown = false
RegisterNetEvent('okokTextUI:Open')

AddEventHandler('okokTextUI:Open', function(message, color, position)

    if not intShown then

    intShown = true

    Open(message, color, position)

    end

end)

RegisterNetEvent('okokTextUI:Close')

AddEventHandler('okokTextUI:Close', function()

    if intShown then

    intShown = false

    Close()

    end

end)

Just did this ^^

Still flickering. Also did debug:

So the problem seems to be with the elseif that checks if they are no longer close, it works flawlessly if i dont have that elseif checking distance away… but how should i hide it then? @Dvergar

So first I would change the elseif to a plain else. Because you are either inrange to display or not.
And I think the issue is your multiple doors. You are inrange for one door, which will trigger the UI. But you are not inrange for all the others you test. This would result in the flickering you experience. To verify you can enhance the print with a door ID or something, then you should see that different doors affect the UI.
You will need something like this:
Show UI if AT LEAST ONE door is in range
Hide UI if no door is in Range AND UI was shown.

I know we just enhanced the UI tool but this only makes sure it is not flickering when multiple show UIs are called. We have to handle now multiple doors.

Okay let’s do it. How do we begin?