Can someone explane how remote events work and why do I need to use them?

I am trying to learn remote events, I tried going to the roblox developer website but nothing there really helps me, can someone explane how to use them and how do they work?

5 Likes

well in the old days of roblox there was filtering disabled which meant everything happened in your client goes sent to server then seen by all players, hackers exploited this thing and just set their money to 999999999999999 then boom they literally can do everything they want like an god.

then filtering enabled came out which means everything happened in your client you can only see them,

just go ahead and make a localscript in startergui and write Instance.new("Part", workspace) then you will see a brick on your screen but at the top there is a client and server tabs, click the server one and boom the part is gone.

so how do i contact server like say i bought a sword for 1 cash? remote events. just make a remote event in replicatedstorage and add game.ReplicatedStorage.RemoteEvent:FireServer("hi") on that local script you created then make a server script in workspace with the code

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(sender, message)
print(sender, "says", message)
end)

and it will print playername says hi just play with this example and youll figure it out

also one more example:

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(sender, message)
print(sender, "says", message)
Instance.new("Part", workspace)
end)

using this code you can make a part that can be seen by all players not only yours

6 Likes

I Have tried using your script and it doesn’t print anything.

1 Like

Can you give me a screenshot of your explorer so i can take a look at.

1 Like

Heres the picture of the explorer:
image

1 Like

there is no localscript in startergui make a one in it and write game.ReplicatedStorage.RemoteEvent:FireServer(“hi”)

1 Like

Remote events are a sort of feature in roblox which allow communication from scripts. Theirs many ways you can use it. It prevents exploiters from messing everything up in your game, even though they diminish is roblox security increases their still a problem. If you ever tried to change something with a local script you’ll be disappointed to notice it doesn’t effect the game. For example deleting a part with a local script would delete it for the local player not everyone. This is where local scripts come in. If you need to communicate from the client and server without exploiters being a problem then if you use a remote event one script waits for it to be sent and does an action when its received. The other sends the request. The advantages is that with it you can do things like notify everyone in the server for something etc… If you haven’t already seen this it should help.
Remote Functions and Events

Here’s an example of what I mean. This is a local script

local remoteEvent = game.ReplicatedStorage:WaitForChild("RemoteEvent")
remoteEvent:FireServer()

In the first line we’re defining the remote event. The remote event must be in a place where local scripts and regular scripts can access which is why its usually in the replicated storage.

Next you’ll need a normal script.

local function RandomName() -- Creating a function
       print("Test")
end

Now that we have a function we can use a simple line to detect it and fire the function.

remoteEvent.OnServerEvent:Connect(RandomName)

Now that we have these two scripts if you play the game it should print(“Test”)

This is just an example of remote events. It’s quite essential in any game really.
You can also send variables through the events but you don’t need to worry about that but if you do then check out a video about it.

6 Likes

I Tried changing some stuff with the script and here is what I made:

local p = game.Players.LocalPlayer
local c = script.Parent
local h = c.Humanoid
p.CharacterAdded:Connect(function()
	game.ReplicatedStorage.Welcome:FireServer("hi")
	local tw = game:GetService("TweenService")
	local tab = {}
	tab.Position = UDim2.new(0,0,0,0)
	local ti = TweenInfo.new(3,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut,3,true,0)
	local fin = tw:Create(game.StarterGui.ScreenGui.TextLabel,ti,tab)
	fin:Play()
end)

for some reason i don’t know why it isn’t working

1 Like

btw thank you for explaning how it works.

1 Like

Let’s say that you want to make a GUI on the server (the game) sync up with a GUI on the client (the player). You cannot just change the GUI on the server through the client, because filtering enabled stops you from doing so.

The solution to this problem is using remote events. Remote events allow you to bypass filtering enabled and fire events on the server through the client, and vice versa.

In this scenario, we can fire the remote event and pass the GUI whenever the GUI changes on the client, and hook the remote up to a server script that changes the GUI to the GUI that got passed through the event.

So what should I Change in the script?

What script? I was explaining what remote events are

oh thought you were talking about something else

Please research the topic on Roblox’s Developer Hub or search for related topics in the fourm before posting.
I understand your confusion but these sort of questions have been answered before:

https://devforum.roblox.com/t/working-with-remotes-and-the-client-server-boundary/453080/2

https://devforum.roblox.com/t/what-is-the-best-way-to-understand-clients-and-servers/770108/39