Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What does the text :Connect mean in scripting?

Asked by 4 years ago

When I look at scripts, I see something say :Connect What does it mean? Why do you need to use it in Roblox Studio? Why is it useful? I want to know why.

If you have the solution, Thank you!

Sincerely, Ducksneedhelp

2 answers

Log in to vote
1
Answered by 4 years ago

:Connect 'connects' a function to an event, so when the event happens, the function is triggered. For example, look through this script:

local function yeet(hit) --Function that prints the part that hit
    print(hit)
end

script.Parent.Touched:Connect(yeet) --[[Connects function to Touched event, 
so the function will run every time the part is hit]]--

:Connect can be used with other events as well. More info can be found on the Roblox Wiki: https://developer.roblox.com/en-us/articles/events

0
Thank you for helping me learn about :Connect! Now I've learned what is it and what you use it for. Thank you again! Sincerely, Ducksneedhelp Ducksneedhelp 129 — 4y
0
No problem! :D HappyRobloxFish 22 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

I'd like to say that connect is a function of events, but I don't know if that's true. I'd also like to say that events are properties of whatever they are a part of, but that's not entirely true either. Events are their own thing. One event of Players is Players.PlayerAdded. When it's fired, a.k.a. someone joins, it's fired with the player object.

Players.PlayerAdded:Connect(function(player) end)

lets you work with every player that will be in your game. It's also worth noting that these events firing won't yield anything in your script. They run on their own, meaning you can have infinite loops both under the function for PlayerAdded and in other parts of the script, both running at the same time. You can also achieve this affect using the spawn function

0
You also helped me out Ducksneedhelp 129 — 4y

Answer this question