How To Use Return?

I have been a bit confused by the use of return. I kind of know how it works, but don’t understand it enough to know when to use it all of the time.

Like:

repStorage.RemoteEvent.OnServerEvent:Connect(function()
if value.Value == true then
return true -- returning a true value to the script that fired the event
else
return false  -- returning a false value to the script that fired the event
end
end)

Is that sort of thing gonna work?

If not, my question is how would I return a value to a script that fired the remote event, like returning a true value from a ServerScript to a LocalScript?

Many thanks!

Use RemoteFunctions.

The format for RemoteFunctions is as follows:

game.ReplicatedStorage.RemoteFunction.OnServerInvoke = function(Player, ...)
    return true
end)

RemoteEvents cannot return values, whereas RemoteFunctions can and do.

2 Likes

Ah yes, a great way of doing this. Thanks!