Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Where can I learn about FE and Remote Functions?

Asked by 6 years ago

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

1 answer

Log in to vote
0
Answered by
xEiffel 280 Moderation Voter
6 years ago
Edited 6 years ago

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

0
That is an amazingly thorough answer. Thank you I really appreciate it. I'll check out the links you have provided. I'm curious though, as to what I'm doing, a player drinks a soda and has the WalkSpeed increased, would this need a remote event to handle it or am I okay just having a local script within the soda tool to increase the player's speed? Thank you again RetroSpock 10 — 6y
0
^ He just copy and pasted a page of the wiki :P Wiscript 622 — 6y
0
I just want to know if I need a remote event or a remote function to manipulate the player's speed (drink soda, run fast for 10 seconds). It sounds like a remote function to me but I don't know as it seems to work with a remote event too :S RetroSpock 10 — 6y
0
Both are fine really, as I said It is recommended to use RemoteFunctions if the code needs a response, otherwise RemoteEvents should be used. But, I would recommend RemoteEvents to change the walkspeed. xEiffel 280 — 6y
View all comments (3 more)
0
Also most of it is taken from the wiki, the scripts and some of the information. The parts that are are credited. (So not all of it is rod) xEiffel 280 — 6y
0
Ty Eiffel, I'll have a toy around and see what I can piece together. It still isn't clicking in my head so trying to use Remotes is like swimming in treacle when I just want to get from A to B. Hopefully it'll make sense eventually after a lot of brute force and trial and error RetroSpock 10 — 6y
0
Yeah, good luck! xEiffel 280 — 6y
Ad

Answer this question