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.
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.