Jump to content

[HELP] attempt to call global 'TriggerClientEvent' (a nil value)


CouldnoT

Recommended Posts

Hello kind reader, i hope you have a great day!

I'm making my first steps to create a login panel, and I just started learning the Gui basics, but I'm failing to Export the Gui from client side.

Here is my script ( it's not complicated at all :

Client side

local login = {};

function login_show()
    login[1] = guiCreateWindow (0, 0, 0.5, 0.4, "Information", true);  
    login[2] = guiCreateTabPanel (0, 0.1, 1, 1, true, login[1]);      
    login[4] = guiCreateTab("Map Information", login[3]);                
    login[5] = guiCreateTab("Help", login[4]);                          

    -- adds a label (text) to each tab
    guiCreateLabel(0.02, 0.04, 0.94, 0.2, "This is information about the current map", true, login[4]);
    guiCreateLabel(0.02, 0.04, 0.94, 0.92, "This is help text.", true, login[5]);
end;
addEvent("loginshow", true); 
addEventHandler("loginshow", root, login_show); 



function login_delete()
    for i,k in ipairs(login) do
        if login[i] then
            guiSetVisible(login[i], false);
        end;
    end;      
end;
addEvent("logindelete", true); 
addEventHandler("logindelete", root, login_delete);  

 

Serverside

 

function LoginPanelShow()
	TriggerClientEvent(Player, "loginshow");
end

function LoginPanelDelete()
	TriggerClientEvent(Player, "logindelete");
end

addCommandHandler("test1", LoginPanelShow);
addCommandHandler("test2", LoginPanelDelete);

 

I greatly thank you for your attention!

Link to comment
  • Moderators

Hi.

1) TriggerClientEvent is not a valid function, correct is triggerClientEvent.
2) Player variable is not defined (so it's nil) in LoginPanelShow and LoginPanelDelete.
3) Third argument is missing in triggerClientEvent, check syntax on wiki.

 

-- CLIENT

local login = {};

function login_show()
    login[1] = guiCreateWindow (0, 0, 0.5, 0.4, "Information", true);  
    login[2] = guiCreateTabPanel (0, 0.1, 1, 1, true, login[1]);      
    login[4] = guiCreateTab("Map Information", login[3]);                
    login[5] = guiCreateTab("Help", login[4]);                          

    -- adds a label (text) to each tab
    guiCreateLabel(0.02, 0.04, 0.94, 0.2, "This is information about the current map", true, login[4]);
    guiCreateLabel(0.02, 0.04, 0.94, 0.92, "This is help text.", true, login[5]);
end;
addEvent("loginshow", true); 
-- listen to those events, which source is 'resourceRoot'
addEventHandler("loginshow", resourceRoot, login_show); 



function login_delete()
    for i,k in ipairs(login) do
        if login[i] then
            guiSetVisible(login[i], false);
        end;
    end;      
end;
addEvent("logindelete", true); 
addEventHandler("logindelete", resourceRoot, login_delete);  
-- SERVER

-- addCommandHandler pass the player's element to function at first argument. (only on server side, check addCommandHandler's syntax on wiki)
function LoginPanelShow(Player)
  	-- send this trigger to 'Player', and use 'resourceRoot' as source of the event
	triggerClientEvent(Player, "loginshow", resourceRoot);
end

function LoginPanelDelete(Player)
	triggerClientEvent(Player, "logindelete", resourceRoot);
end

addCommandHandler("test1", LoginPanelShow);
addCommandHandler("test2", LoginPanelDelete);

 

And here is some excellent tutorials:
https://forum.multitheftauto.com/topic/64228-the-ultimate-lua-tutorial/
https://forum.multitheftauto.com/topic/121619-lua-for-absolute-beginners
https://forum.multitheftauto.com/topic/95654-tut-debugging/
https://forum.multitheftauto.com/topic/114541-tut-events/
https://forum.multitheftauto.com/topic/117472-tut-scaling-dx/

Edited by Patrick
  • Like 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...