Very confused with Remote Events

Hello I am back at it.

I have been reading the roblox wiki about remote events and now I am just absolutely confused.

What am I supposed to do in the LocalScript in StartPlayerScripts and what am I supposed to do in ServerScriptService

StarterPlayerScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local remoteEvent = ReplicatedStorage:WaitForChild("Remote_1")

local Player = game:GetService("Players")
local GUI = Player.LocalPlayer

local UIs = GUI.PlayerGui:WaitForChild("Board_1")

UIs.TextButton.MouseButton1Click:Connect(function()
	
	print("Worked")
	
	wait(1)
	
	local White_Board_1 = workspace.White_Boards.White_Board_1
	
	White_Board_1.SurfaceGui.ImageLabel.Image = "rbxassetid://".. script.Parent.Parent.ID.Text
	
	wait(1)
	
	script.Parent.Parent:Destroy()
end)

ServerScriptService
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local remoteEvent = ReplicatedStorage:WaitForChild("Remote_1")

local Player = game:GetService("Players")
local GUI = Player.LocalPlayer

local UIs = GUI.PlayerGui:WaitForChild("Board_1")

remoteEvent.OnServerEvent:Connect(function(player)
	
end)

Well, I just do not understand what to do, any help would be appreciated :slight_smile:

2 Likes

Do you understand what a local script is?

2 Likes

Yes, I do (30 charsssssssssssssssssssssssssss)

1 Like

So, in the LocalScript just reference the RemoteEvent and use the :FireServer(Tuple) function and in the server script just reference the same RemoteEvent and use the .OnServerEvent:Connect(function) Event, not more. Please follow these 3 steps in this exact order:

  1. I want to learn something and try it alone first

  2. If this is not possible, I try to understand the problem with the Debuggers Tools/print function and on Youtube

  3. But if that still doesn’t work, I come here and ask my question

I know this can be boring and quite annoying, but it is important to try things yourself before asking others

1 Like

The wiki has a good article about this. Basically, you can use FireServer(...) on the client to trigger the OnServerEvent on the server with the arguments of (playerWhoFiredTheEvent, ...). So, if you want to tell the server you clicked a button, you could do Remote_1:FireServer() inside the MouseButton1Click event. Then, on the server, in this connected function:

… you could do whatever stuff you want to happen when a player clicks a button.

3 Likes

What you mean is, in the ServerScript, that is where I do all the functions?

1 Like

You can not use “game.Players.LocalPlayer” in a normal script. It is special for a local script. and why do you call your GUI like Player?
You should learn more about Remote Events & Functions here: Custom Events and Callbacks | Documentation - Roblox Creator Hub
Also you can watch a YouTube tutorial video. I recommend you to watch this: https://www.youtube.com/watch?v=RAP9OTrrep8

2 Likes

If you read the wiki article I linked, it does a good job of explaining it. You use FireServer on the client, and it runs whatever code you have inside the OnServerEvent connection on the server.

4 Likes

Serverscriptservice: You put scripts (not local scripts) in there, so basically everything that can control the server can be parented to the serverscript.

StarterPlayerScript: Local scripts can only be parented to the StarterPlayerScript as Local scripts can only control client side stuff, so when the player joins the game the local script will immediately start to run on that player.

Also for remote events its very simple,

If you want to click a button and tell the server to do something then you’ll need to use the :FireServer() function in the local script and the :OnServerEvent on the script that you wish to catch the signal from.

If you still struggle to understand what I’m saying then:

A Script can use these functions and events: :FireClient(), :FireAllClients(), .OnServerEvent

A Local script can use these functions and events: :FireServer() .OnClientEvent

and if you still don’t understand what I’m trying to say then I recommend you to watch this video as he probably explains better: