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
8 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:

-- all of this is previously defined
folder:WaitForChild("MG"):FireServer(plr, "on")

In the Server Script:

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

2 answers

Log in to vote
3
Answered by 8 years ago

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

function Remote.OnServerEvent(...)
end

Is the same as saying:

Remote.OnServerEvent = function(...)
end

You must use the connect method that binds your function to the event. Take this example:

-- "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.

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

Answer this question