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

How to use the getConnectedParts function?

Asked by 10 years ago

Hello, I am very new to scripting and was wonder how do I use getConnectedParts? Or better, What do I do with pre-made functions.

What I am trying to do:

When block A touches block B a value will decrease.

1 answer

Log in to vote
0
Answered by 10 years ago

No need to use the messy getConnectedParts() method!! Just use the Touched event. Here's an example

local blockA = game.Workspace.blockA --Set this to blockA
local blockB = game.Workspace.blockB --Set this to blockB
local val = game.Workspace.ValueThing --Set this to value to decrease
local decrement = 1 --Set this to how much the value should decrease by

function decrementValue() --Define a function
    val.Value = val.Value - decrement -- Decrease the val by decrement value
end --End function

blockA.Touched:connect(function(hit) --When blockA it hit, this will fire
    if hit == blockB then --Check if the part blockA touched was, in fact, blockB
        decrementValue() --Call function to decrement value
    end --End if
end) --End handler function

[EDIT] I edited this so that the decrementing could be a single function to be called anywhere.

0
A couple quick questions, should I use ";" and how do I call this function if I have to? CaptainRuno 40 — 10y
0
The semicolon is not necessary in Lua, and is, at times, a bad thing, so no, don't use it. NoahWillCode 370 — 10y
0
As for your second question - this isn't a function. It's a handler. I'll edit my answer for making it a call-able funciton. NoahWillCode 370 — 10y
Ad

Answer this question