Jump to content

Client side variables on server side


pa3ck

Recommended Posts

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

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

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

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 by Guest
Link to comment

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

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 :D )

Thanks for the help again, this is a lovely and helpfull community.

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...