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

when do you have to use remote events and parameters ?

Asked by 4 years ago

I have 2 weeks scripting experience and i was kinda confused about knowing what needs a remote event and what doesn't, also when should i use function parameters ?

3 answers

Log in to vote
0
Answered by 4 years ago

Remote events are used for certain interactions between clients, clients to servers, and servers to clients. An example of this would be: when you want to have a certain G.U.I. pop up from touching a part, you would use a remote event because a script can find a G.U.I.

If you don't understand some of it, I'll be happy to explain it more. :)

Ad
Log in to vote
0
Answered by
I_Nev 200 Moderation Voter
4 years ago

Lets say you wanted to have a thing like a base, and a player being able to place on it and or remove items, you'd use events to signal to the server that you'd like to place the item and where, then you have the server check if it is valid and if so then to do it. Or if you wanted to fire a notification to players, you could use an event to fire to clients to send a notification. You can do a lot with events, just make sure they have some kind of validation on the server side else people can manipulate them

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Remote Events Remote Events is an Instance used for communicating between Server to client, client to server, Server to all clients and etc. (But they cannot communicate between server to server and client to client, you would need BindableEvents for that)

For example, I want to create a part globally whenever a button is clicked. You would use remoteevents

button.MouseButton1Click:Connect(function()
    game:GetService("ReplicatedStorage").RemoteEvent:FireServer() --You don't need to set a player parameter, see why later.
end)

Server script

game:GetService("ReplicatedStorage").RemoteEvent.OnServerEvent(player)
    --Whenever you communicate to the server from the client, the first parameter passed automatically is the player.
    Instance.new("Part", workspace)
end)
--And so on

Or if we want to communicate with a client (player) then let's say we want to make a dialogue.

--Server script
script.Parent.MouseClick:Connect(function(player) --Player parameter
    game:GetService("ReplicatedStorage").RemoteEvent:FireClient(player, "Dialogue") --NOTE: The first paramater of :FireClient MUST be the player Instance. The second parameter is to tell the localscript that we want a dialogue.
end)

Client script

game:GetService("ReplicatedStorage").RemoteEvent.OnClientEvent(Type) --In this case, the Type is "Dialogue"
    if Type == "Dialogue" then
        --do thing
    end
end)

You can read the Devhub wiki about RemoteEvents and Functions

Now onto RemoteFunctions: RemoteFunctions are basically callback events. From the client you check on the server then back to the client. Server to client to server isn't recommended though, as it could use up resources. You could use it for checking if a player is new via RemoteFunctions and DataStores. It saves your time of using two RemoteEvents. But that isn't it. Read more here: https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events

Answer this question