[HELP]C# menu not opening without restarting the resource after player joins


I Made a Native UI Menu that works fine. I added in that you have to be in certain locations for the menu to open.
There are makers on the map for you to know were to open it. After testing it when you join the Markers are there but the menu wont open with out restarting the resource

Iam using

Ped playerped = Game.Player.Character;
Vector3 marker = new Vector3(0f, -0f, 0f);

if (World.GetDistance(playerped.Position, marker) < 2f && Game.IsControlJustReleased(1, Control.SelectCharacterMichael))
                    mainMenu.Visible = !mainMenu.Visible;

If i take out the location part it works fine

please if anyone could help


I hope someone has something


pretty easy to debug…

            if (World.GetDistance(playerped.Position, marker) < 2f) {
                Debug.WriteLine("I am within range");
                if(Game.IsControlJustReleased(1, Control.SelectCharacterMichael)){
                    Debug.WriteLine("I am pressing the button");
                    mainMenu.Visible = !mainMenu.Visible;

See what you get and go from there


thank you for replying i just figured it out.
instead of

Ped playerped = Game.Player.Character;

I used

var playerped = API.GetEntityCoords(API.GetPlayerPed(-1), true); 


Alright glad you figured it out, I found it not very logical anyway to do: Ped playerped = Game.Player.Character; and after initialize the Vector3 marker.

May aswel get the player position right away Vector3 playerpos = Game.Player.Character.Position;


I tried Vector3 playerpos and that still made me have to restart the resource


Makes no sense because thats exactly how I do it my mod.


even using
Vector3 playerped = API.GetEntityCoords(API.PlayerId(), true);
made me restart it


this is an example straight from my mod:

foreach (Vector3 v in lst_Bank)
                    if(World.GetDistance(v, Game.Player.Character.Position) < 1)
                        InBankCircle = true;
                        if(Game.IsControlJustPressed(0, Control.Talk))

Works 100 procent never any problems and I do it the same way for clothing stores, jobs etc


and with that i have no idea why my crap didnt want to work right. lol


well sorr :frowning: can’t help you any further then, because it definitely should work. Kind of made me curious on why it doesn’t.


well thank you any way i know i will most likely have future problems.