pa3ck Posted October 2, 2013 Share Posted October 2, 2013 Hi again, is there any way to use client side variables on server side? Like GUI is on client side, I got a text from the GUIEditBox and I would like to use that message on server side, to let everybody see the message he typed in. But I got nil for the variable on server side. Link to comment
Chopper Posted October 2, 2013 Share Posted October 2, 2013 Use: triggerClientEvent from serverside. Link to comment
Skurken Posted October 2, 2013 Share Posted October 2, 2013 Actually it's triggerServerEvent that he needs. triggerServerEvent Link to comment
pa3ck Posted October 2, 2013 Author Share Posted October 2, 2013 Thanks guys for the replies, but I'm still not sure about any of them. What I understood is that, triggerServerEvent triggers an event on server side (I'm genius!). But I'm still not sure how is that going to let me use client side variables. Or can I trigger a whole function like? Link to comment
Skurken Posted October 2, 2013 Share Posted October 2, 2013 You can send a the vars to server-side. triggerServerEvent('event', root, variable) Link to comment
xXMADEXx Posted October 2, 2013 Share Posted October 2, 2013 Here are examples that might help you. Example 1 - triggerServerEvent -- Client local v = math.random ( 0, 9999 ) triggerServerEvent ( "theServerEvent", localPlayer, v ) -- Server addEvent ( "theServerEvent", true ) addEventHandler ( "theServerEvent", root, function ( v ) outputChatBox ( "You have generated "..tostring ( v ) ) end ) Example 2 - triggerClientEvent -- Server local v = math.random ( 0, 255 ) local p = getRandomPlayer ( ) triggerClientEvent ( p, 'theclienteventname', p, v ) -- Client addEvent ( "theclienteventname", true ) addEventHandler ( "theclienteventname", root, function ( v ) outputChatBox ( "You have been picked!! Heres a random number: "..tostring ( v ) ) end ) Link to comment
pa3ck Posted October 3, 2013 Author Share Posted October 3, 2013 Oh, I got it! Thanks very much, appreciated! Link to comment
pa3ck Posted October 3, 2013 Author Share Posted October 3, 2013 (edited) Actually I would have one more question. What if I need to trigger a server side event and a variable as well? What I want to do is if I click on a GUI button an event will be triggered and I will call that event from server side, so something is going to happen. In my case it will output something in the chatbox. What I want to output is a variable from client side, I'm not quite sure how to do that... Could anyone give me an idea? --Client side local idd = guiGetText(skinEdit) skinvEditID = tonumber(idd) triggerServerEvent('boughtSkin', localPlayer, skinvEditID) --Server side addEvent('boughtSkin', true) addEventHandler('boughtSkin', root, function( skinvEditID ) outputChatBox('Server: a guy got a new skin with the ID of: ' .. skinvEditID ) end ) This code is not working, it says skinvEditID is nil, so cant concatinate it. Edited October 3, 2013 by Guest Link to comment
Castillo Posted October 3, 2013 Share Posted October 3, 2013 And what does it return on the client side? have you checked if it isn't also returning 'nil'? Link to comment
pa3ck Posted October 3, 2013 Author Share Posted October 3, 2013 Its funny, it worked then I restarted the script ( made no changes ) and now it says the same thing. And on client side it is working as it sets the player model with this code: setElementModel(thePlayer, skinvEditID) I have no clue whats the problem here. Link to comment
Castillo Posted October 3, 2013 Share Posted October 3, 2013 When exactly are you triggering this event? Link to comment
pa3ck Posted October 3, 2013 Author Share Posted October 3, 2013 When the button is pressed, but I figured it out, thanks for the help, really appreciated! BTW: the code I included was right, the other half of the code was wrong, I got it now! ( shame on me ) Thanks for the help again, this is a lovely and helpfull community. 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