I need help with remote functions/events

. What do I want to achieve? I need help finding out how to use/code remote functions and events

What solutions have you tried so far? I tried watching videos but none of them helped.
My question is if you guys can send some videos for me to watch to learn about remote events and functions?

This is pretty good

1 Like

This is going to be an overly simplified view of what remote functions are. They are just like remote events but they return something back to the client or server who sent it. That’s it. If you wanted to send something from the client to the server then send that processed data from the server back to the client use a remote function. Regarding remote events its just code which runs of the server (or client) and is “fired” or in other words “called” by the client (or server)

1 Like

So since you said use them, I’m assuming you know what they do, so I’ll smooth that over.

RemoteEvents can be triggered and used in several ways. Using:

MyRemoteEvent:FireServer()

and

MyRemoteEvent:FireClient(plr)

Now you can only fire the server via a LocalScript, and you can only fire the client via a ServerScript. When firing a RemoteEvent, you have the choice to send over information within the parenthesis. Now once those events are fired, you can use functions to check if they are fired, examples below.

MyRemoteEvent.OnServerEvent:Connect(Function(plr, gameProccessedEvent) --Those 2 variables are always preset, it gives you the Instance (This is important) of the player, and something else which doesn't matter too much atm.

end)
MyRemoteEvent.OnClientEvent:Connect(Function()--There will be no preset Variables here.

end)

Those are the basics.
When sending something to the client, you need to specify the player Instance, such as.

Example:
Script

script.Parent.Touched:Connect(function(hit)
   myPlayer = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
end)

MyRemoteEvent:FireClient(myPlayer) --Specifies the player

You can send information within RemoteEvents as such
LocalScript

local Hi = true
local Instance = game.Workspace.Part2

MyRemoteEvent:FireServer(Hi, Instance) --Names the Variables and sends them

Now I can interpret these as such.
ServerScript

MyRemoteEvent.OnServerEvent:Connect(function(plr, HiVariable, InstanceVariable)
   print(HiVariable) --Will return true
   print(InstanceVariable.Name) --Will return the name of the instance.
end)

Roblox addresses ways of using Remote Events in this article.

Feel free to ask questions, I hope this helped.

1 Like

Thank you a lot this was very helpful!

Thank you! I will be sure to look at it.

Thank you so much! This helps a lot mostly cause I can use what you said with other replies!