Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to use the getConnectedParts function?

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

✓ Accepted answer

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.

3 comments

0

A couple quick questions, should I use ";" and how do I call this function if I have to?

0

The semicolon is not necessary in Lua, and is, at times, a bad thing, so no, don't use it.

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.