I've been trying to communicate between Clients and Servers via RemoteEvent. However, when I try to make a "function (remoteEvent Name).OnServerEvent()", there is an error saying "OnServerEvent is not a valid member of RemoteEvent". Please help, here is the code.
In the Client Script:
1 | -- all of this is previously defined |
2 | folder:WaitForChild( "MG" ):FireServer(plr, "on" ) |
In the Server Script:
1 | function folder.Reload.OnServerEvent(onOrOff) |
2 | -- code |
3 | end |
As eLunate said, OnServerEvent
is an Event
, not a callback
. Saying something like:
1 | function Remote.OnServerEvent(...) |
2 | end |
Is the same as saying:
1 | Remote.OnServerEvent = function (...) |
2 | end |
You must use the connect
method that binds your function
to the event
. Take this example:
1 | -- "Client" is automatically defined as the player of the local script who called the function. The first argument of this event will ALWAYS be the local player. |
2 |
3 | Remote.OnServerEvent:connect( function (Client,...) |
4 | end ) |