Introduction to RbxScriptConne

Introduction to a major part of roblox scripting

by ViniDalvino

Author Avatar

Event or RbxScriptSignal are a major part of roblox scripting and what make roblox lua different from others version of lua. In this guide we will talk about the following things:

  1. **What are RbxScriptSignal**
    
  2. **How to use RbxScriptSignal**
    
  3. **Tips and trick about using them**
    

Information about this guide:

In this guide you will see indicator such as the following :

Hello, world![1]

The [1] will mean to go at the end of the article and to check what is the definition. Go at the end of the article to see an example of the meaning of the "Hello world"

1. What are RbxScriptSignal

RbxScriptSignal are a way for Instance[2] to create event that will fire[3] function when a event[4] in the instance ocure.

2. How to use RbxScriptSignal

You must know that in order to use RbxScriptSignal that it depend on the Instance class; You can't use the following example on a part but you can do it on a button. To know which event are available you have to use the roblox devhub and to know which event are available.

button = script.Parent
button.Activated:Connect(function() print("Clicked!") end)

To sum up, different class have access to different RbxScriptSinal.

Here come the tutorial part: I will explain to you how you can script a part that change another part color when the other part touch the part.

  1. Create a part in the workspace and insert a part. In the part, insert a script.
    

Go on the devhub, search for part and look out for the event called Touched.

img|50x5

To understand this documantation you need to understand the following thing Look at the screen shot. Here is the definition of what the parameter mean:

1: What you need to call the event with. 2: An parameter you will pass to the function that will be called when the event will be fired.

Create a part and a script into the part and define the parent of the script.

part = script.Parent

After defining your part you bind to the part the event. To do the following you define the instance with the event(RbxScriptSingal). It goes as follow:

part.Touched:Connect(function(otherPart)

end)

Let's understand what the function in that snippet mean:

Part: The instance where we bind a event to Touched: The RbxScriptSignal(event) Connect: Establish the RbxScriptConnection to be called when the event is fired function(otherPart): Function is the function that will be called when the event and otherPart is the parameter that we pass on the function. Parameter depend on the function

Now what you will do is use the parameter of the function otherPart to change the color of the part that touched the part.

part = script.Parent

part.Touched:Connect(function(otherPart) 
    otherPart.BrickColor = BrickColor.random()
end)

Congrat you made your first script using RbxScriptConnection and you learned how to use them.

3. Tips and trick about RbxScriptConnection:

Definition:

[1] Hello, world: Sentence used to check if a compiler or a scripting language is working correctly. [2] Instance: The base class of all others class in roblox [3] Fired: Expression commonly used meaning triggering something [4] Event: Synonym for RbxScriptConnection