I understand what they're for, I just can't figure out how to implement them into my game.
My son is my beta tester for any changes I make and sometimes he says stuff doesn't work, but it works fine in Studio, I'm assuming this is due to FE being on and I'm not using remote functions etc.
At the moment I'm experimenting with drinks (drinking a soda will make you run fast). How would I use Remote Functions for that?
Thanks
note[wiki]: It is recommended to use RemoteFunctions if the code needs a response, otherwise RemoteEvents should be used.
Filtering Enabled makes everything localised, preventing most exploits, as you probably already know. To combat this to making something server-side with FE on, you should be using Remote Functions, as you said.
In order for both the server and clients to utilize RemoteFunctions, the RemoteFunction object itself must be in a place where both can see it. It is recommended to store RemoteFunction in a folder inside of ReplicatedStorage, although in some cases it is appropriate to store events in the Workspace or in Tools. You should have 2 script-types, a 'LocalScript' and a 'Script' aka. a 'Server-Side Script'.
Remote Functions
It is important to note that invoking remote functions, either on the server or client, will yield until the remote function’s callback finishes executing or returns. This means that while code in other threads on the machine that invoked the function can run, code in the same thread as the invoke will not execute until the invocation is done. ~ Wiki
First there are signals you have to send through the client or server, In this case there are 2 you can do this by:
:InvokeServer()
:InvokeClient()
Let's start with :InvokeClient();
Clients invoking the server is often used because the server either has access to information the client does not, or the client is requesting a game action that only the server can perform. Going the other way (the server invoking a client) is not done often in practice. Clients typically do not have information the server doesn’t have and the actions that only a client can take (displaying a GUI for instance), often do not require a callback. That said, the server invoking clients is still an action that the Roblox engine will support and may be useful in niche situations. ~ Wiki
You would place this in a regular Server-Side script; Script provided by Roblox Wiki.
-- Script local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local createPopupRequest = Instance.new("RemoteFunction") createPopupRequest.Name = "CreatePopupRequest" createPopupRequest.Parent = ReplicatedStorage Players.CharacterAutoLoads = false local function onPlayerAdded(player) createPopupRequest:InvokeClient(player) player:LoadCharacter() end Players.PlayerAdded:Connect(onPlayerAdded)
You would place this in a LocalScript; Script provided by Roblox Wiki. Make sure this is placed in a correct service as this is a LocalScript. StarterGui or StarterPlayerScripts.
-- LocalScript local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local player = Players.LocalPlayer local playerGui = player:WaitForChild("PlayerGui") local createPopupRequest = ReplicatedStorage:WaitForChild("CreatePopupRequest") local function onCreatePopupRequested() local screen = Instance.new("ScreenGui") screen.Parent = playerGui local closeButton = Instance.new("TextButton") closeButton.Text = "Welcome to the game! Click me to play!" closeButton.Size = UDim2.new(0, 300, 0, 50) closeButton.Parent = screen closeButton.MouseButton1Click:Wait() closeButton.Visible = false end createPopupRequest.OnClientInvoke = onCreatePopupRequested
A Remote Function is invoked on the client when that client wants the server to do something, and then wants to be notified that the server is done. This is commonly done to fetch information from the server and then do something with that information, but it can be used in a few other applications.
This will be using the :InvokeServer() Function.
You would place this in a LocalScript; Script provided by Roblox Wiki. Make sure this is placed in a correct service as this is a LocalScript. StarterGui or StarterPlayerScripts.
-- LocalScript local ReplicatedStorage = game:GetService("ReplicatedStorage") local createPartRequest = ReplicatedStorage:WaitForChild("CreatePartRequest") local newPart = createPartRequest:InvokeServer() print("The server created this part for me:", newPart)
You would place this in a regular Server-Side script; Script provided by Roblox Wiki.
-- Script local ReplicatedStorage = game:GetService("ReplicatedStorage") local createPartRequest = Instance.new("RemoteFunction") createPartRequest.Parent = ReplicatedStorage createPartRequest.Name = "CreatePartRequest" local function onCreatePartRequested(player) print(player.Name, "wants to create a new part") local newPart = Instance.new("Part") newPart.Parent = game.Workspace return newPart end createPartRequest.OnServerInvoke = onCreatePartRequested
This will showcase a part in the server positioned above the middle.
Hopefully you understand these subjects better and don't hesitate to ask a question.
Roblox wiki is probably the best place to learn more about Remote Events and Remote Functions you can locate the subject on Remote Events and Remote Functions here, this will be a much better explanation than I've done:
http://wiki.roblox.com/index.php?title=Remote_Events_and_Functions
Here is a subject about Filtering Enabled as well:
http://wiki.roblox.com/index.php?title=API:Class/Workspace/FilteringEnabled