[HELP] Retrieve something from server to client and viceversa

This is the second time I ask this question, but I will explain it better as no one understood what I was looking for.

So, let’s say I want a client script to find a value from a server script and bring it back to the client script. The way I’ve been doing this is as follows:

client.lua:

-- Declare the variable (without the actual value)
value = nil

-- Start the value retrieval process
TriggerServerEvent("test:find")

-- New event to bring the value to this file from the server (called from the server, of course)
RegisterNetEvent("test:bring")
AddEventHandler("test:bring", function(newvalue)
	value = newvalue
end)

server.lua:

-- The value I want the client to retrieve
value = 10

-- Event that starts the whole process (called from the client)
RegisterServerEvent("test:find")
AddEventHandler("test:find", function()
        -- Finally send the value to the client!
	TriggerClientEvent("test:bring", value)
end)

So this is the absolutely annoying way I use to retrieve a value from server to client or viceversa. There must be a damn easier way to do this.

Any idea is appreciated. :slight_smile:

At the minute this is the only way that I know of to achieve this. The Devs are working on a system in which you can run clientside code on the server and viceversa. They haven’t said when it will be released (soon :tm: ) but, it look nicer than calling two events.

From the Discord:

1 Like

Okay, thank you!

The update you say they’re working on sounds great, I hope it’ll be released soon…

By the way, could you tell me who said it? Just to see the entire post to know more about it. Thanks in advance

this has in fact already been shipped and should work, you still need to call an event on one side to bring the API across though

1 Like

Oww nice, is there any reference or somewhere I can find out how to do it?

@iridium Would it allow me then, to spawn cars server side? Like without having to do it from someone’s client.