Ioannis20x Posted June 18, 2021 Share Posted June 18, 2021 Hello, today i tried to bind a key when a player connects to the Server(client side) but it dont worked. Now i want to bind the Key onPlayerConnect in server side. But the function can only run client side. My question: how to call a client side function on server side and what is the best method to do this? Link to comment
βurak Posted June 18, 2021 Share Posted June 18, 2021 (edited) hello you can use events you can create an event on client side and run it with triggerClientEvent on server side example: server addEventHandler("onPlayerJoin", root, function() triggerClientEvent(source, "testEvent", source) -- execute event end ) client addEvent("testEvent", true) addEventHandler("testEvent", root, function() --do something here end ) or you can browse this script of IIYAMA I also suggest you to use "onPlayerJoin" Event for key binding. Edited June 18, 2021 by Burak5312 Link to comment
SpecT Posted June 19, 2021 Share Posted June 19, 2021 (edited) Hey, There is a chance the player to get an error - the client side event is not attached to any function. When the "onPlayerJoin" is triggered the player might still be downloading -> the player still doesn't have the client side loaded -> error. I don't get it why would you want to bind the key in the server side and "onPlayerConnect". It would have had more logic if it was onPlayerLogin (i.e. to check if has enough rights but you didn't mention something like that). Anyways you can easily put the bindKey function in the client script out of any functions and it will bind the key on client resource load. function asd() -- something end bindKey("F1", "down", asd) Or use the onClientResourceStart event. Edited June 19, 2021 by SpecT Link to comment
βurak Posted June 19, 2021 Share Posted June 19, 2021 6 hours ago, SpecT said: There is a chance the player to get an error - the client side event is not attached to any function. When the "onPlayerJoin" is triggered the player might still be downloading -> the player still doesn't have the client side loaded -> error. you're right, i didn't think about that Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now