In this tutorial, I will go over:
Please comment if I missed anything, and without further ado, let's begin!
---------------------------------------------------------------------------------
Setting up your workspace
To start, begin with a blank project (or an existing one, whichever you feel like), and place a part on your baseplate.
In the Explorer, navigate to Workspace -> (Name of the part you entered, default is "Part")

Right click, and navigate to Insert Object -> Click Detector, and insert it.

Now, right click on Workspace, and navigate to Insert Object -> RemoteEvent, and insert it.
Then, right click on the RemoteEvent you just created, and navigate to Insert Object -> Script (not Local), and insert it.

And finally, right click on StarterGui, and navigate to Insert Object -> LocalScript, and insert it.

Open the LocalScript you just created, and it's finally time to code!
---------------------------------------------------------------------------------
This next part is designed for you to actually learn Lua, so if you don't care for that, just copy-paste this into the LocalScript:
---------------------------------------------------------------------------------
Programming the LocalScript
We need to start by declaring a variable, and we will do that by entering
We will set this equal to
The whole variable should look something like this:
Next, we need to detect if the user clicks the part. The code looks like this:
The "end)" will be automatically produced for you.
"clickDetector", the variable we just set checks if your mouse clicked the Part, in "MouseClick". We continue this by entering ":Connect", which connects with the RemoteEvent's script to trigger the function we will put in it in just a moment. Then "(function()" declares that we want this event to be a function. Be careful not to close the outer parentheses, as that is what the parentheses after the automatically generated "end)" is for.
Inside the function, there will only be one line of code, and it is:
The only new thing in here is ":FireServer()". This is what sends the signal to the remote event to call the function.
That's it for the LocalScript!
---------------------------------------------------------------------------------
This next part is also designed for you to actually learn Lua, so if you don't care for this either, just copy-paste this into the Script:
---------------------------------------------------------------------------------
Programming the Script
Inside the script, we need to recieve the signal sent by the LocalScript we just programmed to do this. This will also be a ":Connect" function, and it looks like this:
The only new thing here is "OnServerEvent". This is what responds to "FireServer()" in the LocalScript.
From here, feel free to add your own code inside this, as there's nothing left to activate the RemoteEvent. Congratulations on surviving this tutorial!
---------------------------------------------------------------------------------
Video tutorial, with minor differences
---------------------------------------------------------------------------------
- How to detect when a user clicks a part using ClickDetector
- How to send a request through RemoteEvent
- How to read the request inside of another script
Please comment if I missed anything, and without further ado, let's begin!
---------------------------------------------------------------------------------
Setting up your workspace
To start, begin with a blank project (or an existing one, whichever you feel like), and place a part on your baseplate.
In the Explorer, navigate to Workspace -> (Name of the part you entered, default is "Part")

Right click, and navigate to Insert Object -> Click Detector, and insert it.

Now, right click on Workspace, and navigate to Insert Object -> RemoteEvent, and insert it.

Then, right click on the RemoteEvent you just created, and navigate to Insert Object -> Script (not Local), and insert it.

And finally, right click on StarterGui, and navigate to Insert Object -> LocalScript, and insert it.

Open the LocalScript you just created, and it's finally time to code!
---------------------------------------------------------------------------------
This next part is designed for you to actually learn Lua, so if you don't care for that, just copy-paste this into the LocalScript:
Lua:
local clickDetector = game.Workspace.Part:WaitForChild("ClickDetector")
clickDetector.MouseClick:Connect(function()
game.Workspace.RemoteEvent:FireServer()
end)
---------------------------------------------------------------------------------
Programming the LocalScript
We need to start by declaring a variable, and we will do that by entering
local clickDetector =
. "local" means that the variable can only be accessed from that script and not others, and "clickDetector" is the name of the variable. Feel free to change that to whatever you want, but you will need to use it in the next step.We will set this equal to
game.Workspace.Part:WaitForChild("ClickDetector")
. "game" is the folder that includes anything you can see in the explorer (and more!), "Workspace" is a child of "game", which we put the Part and RemoteEvent in earlier. "Part" is a child of Workspace, and it is the part that we entered the ClickDetector into. Change this to the name of your part. ":WaitForChild("ClickDetector")" waits for the ClickDetector, a child of the Part we entered, to load in for the user and then functions as if we would just directly state "Part.ClickDetector". You can learn more about this here.The whole variable should look something like this:
Lua:
local clickDetector = game.Workspace.Part:WaitForChild("ClickDetector")
Next, we need to detect if the user clicks the part. The code looks like this:
Lua:
clickDetector.MouseClick:Connect(function()
end)
"clickDetector", the variable we just set checks if your mouse clicked the Part, in "MouseClick". We continue this by entering ":Connect", which connects with the RemoteEvent's script to trigger the function we will put in it in just a moment. Then "(function()" declares that we want this event to be a function. Be careful not to close the outer parentheses, as that is what the parentheses after the automatically generated "end)" is for.
Inside the function, there will only be one line of code, and it is:
Lua:
game.Workspace.RemoteEvent:FireServer()
The only new thing in here is ":FireServer()". This is what sends the signal to the remote event to call the function.
That's it for the LocalScript!
---------------------------------------------------------------------------------
This next part is also designed for you to actually learn Lua, so if you don't care for this either, just copy-paste this into the Script:
Lua:
game.Workspace.RemoteEvent.OnServerEvent:Connect(function()
end)
Programming the Script
Inside the script, we need to recieve the signal sent by the LocalScript we just programmed to do this. This will also be a ":Connect" function, and it looks like this:
Lua:
game.Workspace.RemoteEvent.OnServerEvent:Connect(function()
end)
The only new thing here is "OnServerEvent". This is what responds to "FireServer()" in the LocalScript.
From here, feel free to add your own code inside this, as there's nothing left to activate the RemoteEvent. Congratulations on surviving this tutorial!
---------------------------------------------------------------------------------
Video tutorial, with minor differences
---------------------------------------------------------------------------------
Last edited: