Wait for the server answer


#1

Hi there !

I’m looking for advice. For now, when I want to stop the script until the server trigger my event, I do

local running = true
TriggerServerEvent("event2")...
while running do
wait(200)
end

RegisterNetEvent("event1")...
AddEventHandler("event1")...
running = false

Server side :

Register("event2")
EventHandler("event2")
TrigerClientEvent("event1")

There is another way to wait for the server answer actually in Lua ?


#2

What? What are you trying to achieve? Events are executed when they are called… You don’t need to wait.

For example:
Client

TriggerServerEvent("someEvent") -- Trigger the server's event 

RegisterNetEvent("event2") -- Make sure "event2" can be trriggered from server
AddEventHandler("event2", function() -- Handler for the event
   -- Do something
end) 

Server

RegisterServerEvent("someEvent") -- Make sure event can be triggered from client
AddEventHandler("someEvent", function()
   -- Do something
   TriggerClientEvent("event2", source) -- Trigger event two on the original client
end)

#3

So that way, You are already waiting for the server answer ?
Thanks you ! :smiley: