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

When do you use Remote Functions?

I always used Remote Events for my scripts and I thought "I should use Remote Functions.". When should I use Remote Functions?

2 comments

0

They work in the same way as remote events but they return a value.

0

When you don't want to use value objects to display values from scripts, so you use an invoke or an event to distribute information along the server. In my opinion values are better.

2 answers

✓ Accepted answer

###You should use RemoteFunctions when you want to return something, such as the price of a car in game. RemoteFunctions are for two way communication, while RemoteEvents are only for one.

#Example: ###Script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local CheckPrice = ReplicatedStorage:WaitForChild("GetPrice")
local GetPrice 

GetPrice = function(player, carName)
    return game.Workspace[carName].Price.Value
    -- IntValue inside car named price
end

CheckPrice.OnServerInvoke = GetPrice

###LocalScript

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local CheckPrice = ReplicatedStorage:WaitForChild("GetPrice")
local Price = CheckPrice:InvokeServer("Car")

print(Price) --> 2500 (Its price is 2500)

Well, basically everything in the game is owned by the server, so remote functions would basically return a vaule by the server from the item you're requesting.

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