Is there a way to get the data sent over by a remote event and use it on the receiving script outside of the receiving function?

I want to be able to get the data sent over by a remote event and use it for anything in the receiving script.

Like getting the data outside of the event to use in the script itself.

A text example would be this.
(ServerScript) (localScript)
remoteEvent(data) —> remoteEvent(data) —> receivingScript(data)

Hopefully you understood what I’m aiming for here. Thanks in advance.

I guess just do this:

Create a variable in your script and set it to nil.
Then when the RemoteEvent is fired, set that variable you made to the RemoteEvent data you received.
When you want to use the data, check if your variable that stores it is not nil, meaning the event was fired. If it is not nil, then use that data.

Here’s a code example:

local data = nil
remote.OnServerEvent:Connect(function(myData)
	data = myData
end)

if data ~= nil
    doStuff()
end

Sorry if I misunderstand. Hopefully this helps!

Just to make sure. doStuff() is the function that I make that does stuff when data isn’t nil correct? I think this might solve my problem/question, thanks for the help I’ll see if this works! :slight_smile:

Yup!

Good luck, if anything’s wrong tell me.