Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

OnServerEvent is not a valid member of RemoteEvent?

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

2 comments

0

To listen for OnServerEvent, your script needs to be a Script, and vice versa.

0

My mistake, the second line of code is in the Server Script.

2 answers

✓ Accepted answer

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)

1 comment

0

Thanks. It works now, and thank you for explaining it more in-depth than eLunate did.

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

1 comment

0

Still doesn't work.

This discussion is preserved as it was. New answers, comments, and votes are closed.