Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Events fired and received in the same script?

Asked by 8 years ago

I was wondering if it was possible to both fire an event and have code prompted by it in the same script. I'm using several coroutines in the same script, and I"m thinking it would be a lot easier to communicate between them if this were possible.

local event = Instance.new("RemoteEvent",game.ReplicatedFirst)

coroutine.resume(coroutine.create(function()
    event.OnServerEvent:connect(function(message)
        print(message) --prints nil?
    end)
end))

event:FireServer("hello!")

The event does seem to fire here, but it's not returning the value passed to it. Maybe I'm just doing it wrong?

1 answer

Log in to vote
0
Answered by 8 years ago

I solved it myself.

local event = Instance.new("RemoteEvent",game.ReplicatedFirst)

coroutine.resume(coroutine.create(function()
    event.OnServerEvent:connect(function(nothing,message)
        print(message)
    end)
end))

event:FireServer("hello!")

The listener takes the client as the first parameter, and the given parameters as the next ones.

If you know a more efficient method, however, please don't refrain from telling me.

Ad

Answer this question