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

OnServerEvent is not a valid member of RemoteEvent?

Asked by
u_g 90
9 years ago

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
2folder:WaitForChild("MG"):FireServer(plr, "on")

In the Server Script:

1function folder.Reload.OnServerEvent(onOrOff)
2 -- code
3end
0
To listen for OnServerEvent, your script needs to be a Script, and vice versa. TheDeadlyPanther 2460 — 9y
0
My mistake, the second line of code is in the Server Script. u_g 90 — 9y

2 answers

Log in to vote
3
Answered by 9 years ago

As eLunate said, OnServerEvent is an Event, not a callback. Saying something like:

1function Remote.OnServerEvent(...)
2end

Is the same as saying:

1Remote.OnServerEvent = function(...)
2end

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 
3Remote.OnServerEvent:connect(function(Client,...)
4end)
0
Thanks. It works now, and thank you for explaining it more in-depth than eLunate did. u_g 90 — 9y
Ad
Log in to vote
1
Answered by 9 years ago

OnServerEvent is an Event, and not a callback. You'll need to do OnServerEvent:connect(func) instead of OnServerEvent = func

0
Still doesn't work. u_g 90 — 9y

Answer this question