Sign in to follow this  
Donny7878

Triggering a client event

Recommended Posts

Server:

addEventHandler( "onPlayerJoin", getRootElement(),
function ()	
	outputChatBox( "Welcome " .. getPlayerName ( source ) .. " to the test server" , source, 255, 255, 255 )			
	fadeCamera( source, true )	
	setCameraTarget( source )
	spawnPlayer( source, 0.0, 0.0, 3.0, 0.0 )	
	triggerClientEvent( source, "onRequestBuildGUI", getRootElement() )
end
)

Client:

addEvent ( "onRequestBuildGUI", true )
addEventHandler ( "onRequestBuildGUI", getRootElement(), CreateGUI )
 
function CreateGUI( source )		
outputChatBox ( "The CreateGUI function fired", 255, 255, 255 )	
end

Just trying to trigger the CreateGUI function when the player joins and send the message (currently) but for some reason I'm getting nothing. I debugged the trigger and it is sending the event trigger (returned true) but the client never seems to get the call or doesn't want to fire the event, could you tell me why ?

I have been working from this page on the Wiki -> TriggerClientEvent

Share this post


Link to post

when the player joins the server (onPlayerJoin triggers) they havent necessarily finished downloading the clientside scripts, so you may end up trying to trigger a client event that simply does not exist yet

you can use onClientResourceStart clientside to achieve what you are trying to do, it is triggered when the player finishes downloading the client script when they join the server

function CreateGUI()
outputChatBox ( "The CreateGUI function fired", 255, 255, 255 )   
end
addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),CreateGUI)

Share this post


Link to post
when the player joins the server (onPlayerJoin triggers) they havent necessarily finished downloading the clientside scripts, so you may end up trying to trigger a client event that simply does not exist yet

you can use onClientResourceStart clientside to achieve what you are trying to do, it is triggered when the player finishes downloading the client script when they join the server

function CreateGUI()
outputChatBox ( "The CreateGUI function fired", 255, 255, 255 )   
end
addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),CreateGUI)

Makes sense that, it would explain why some other code isn't working also.

Works perfectly when using your code so cheers for the that and the info, it's apreciated.

Share this post


Link to post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.