Remote functions

RemoteEvents & RemoteFunctions are similiar, Both can be used For Server → Client or Client → Server Communication. The only difference is that RemoteFunctions can return values, Meanwhile RemoteEvents can’t.

For example, Let’s say that you have a Shop in your game, Only players with the Level above 10 can buy a certain item, You would need to check the Player’s level on the Server, As doing it on Client wouldn’t work at all. (Exploits, And can easily be bypassed)

You can use RemoteFunctions for that, Since they can return values and you can check them. Here’s what a simple example of them would look like (Assuming there’s a RemoteFunction called “GetLevel” on ReplicatedStorage):

-- Server Script

-- ReplicatedStorage
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local GetLevel = ReplicatedStorage:WaitForChild("GetLevel")

-- Main

-- This is gonna fire whenever a Player invokes the Server
-- Let's say when they invoke the RemoteFunction (Client → Server)
-- They're requesting the value.

GetLevel.OnServerInvoke = function(Player)
	-- Assuming the Player has a Leaderboard folder...
	return Player.Leaderboard.Level.Value
end
-- Client Script

-- ReplicatedStorage
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local GetLevel = ReplicatedStorage:WaitForChild("GetLevel")

-- Testing
-- We're gonna request the Server to gives us our Level.
local PlayerLevel = GetLevel:InvokeServer()

if PlayerLevel >= 10 then
	-- Code
end
39 Likes