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

How can I cause multiple bricks to unanchor from ClickDetector at once?

I want to create a brick wall that if you click one brick, 70 bricks lose collision and the wall behind vanishes. I have no formal experience with scripting so I need all the help I can get!

Information and Intention for the blocks:

TriggerStone -A regular brick -Has click detector -Want to have it cause all OldBrick and TriggerStone become unanchored upon being clicked

FallibleBricks -A model containing 69 blocks named "OldBrick" -Want to have them all fall when TriggerStone is click

FalseWall -A Union -Want to become transparency 1 and turn off its collision upon TriggerStone being clicked

If you could help out, it would be much appreciated. Thank you.

2 answers

✓ Accepted answer

In using the ClickDetector, you would have to set up a function using MouseClick and a pairs loop using GetChildren() to access all the parts in the model.

TriggerStone > ClickDetector > Script --edit the script depending on how you set up your models and parts.

script.Parent.MouseClick:Connect(function()
	--clicking function done
end)
local FallibleBricks = workspace:WaitForChild("FallibleBricks")
local FalseWall  = workspace:WaitForChild("FalseWall")

script.Parent.MouseClick:Connect(function()
	for i,v in pairs(FallibleBricks:GetChildren()) do --this will get all the parts in the model. v will be defined as the parts in the model.
		v.Anchored = false
		FalseWall.Transparency = 1
		FalseWall.CanCollide = false
	end
end)

2 comments

0

Wow! Well, thank you very much InfernoExeuctioner. This helps me very much.

0

I get that this is a bit of a necrobump, haha, but just as a note: There's no need to include the FalseWall property changes within the loop, just do it beforehand/afterwards, so that you aren't executing those two commands for every brick in "FallibleBricks." Also, a debounce might help keep accidental repetition from occurring as well. Otherwise, good solution!

The way I imagine it is that there's a model, inside that model is the TriggerStone containing the ClickDetector and another model called "FallibleBricks" which contains bricks called "OldBrick".

This script will only work if all of the objects are arranged in that way. Script's parent should be the ClickDetector.

local CD = script.Parent
local TS = CD.Parent
local FB = TS.Parent:WaitForChild("FallibleBricks")

CD.MouseClick:Connect(function()
	TS.Anchored = false
	for i, v in pairs(FB:GetChildren()) do
		v.Anchored = false
	end
end)

Let me explain what the script does. First of all, we define all of the objects. When the ClickDetector gets clicked it unanchors the TriggerStone and then iterates through FallibleBricks' children (OldBrick) and unanchors all of them.

I'm very sorry if I explained something wrong or the script doesn't work. This is my first answer.

3 comments

0

It works well to unanchor the blocks, though it didn't include making FalseWall invisible. Thanks anyways!

0

Oh, I completely forgot about that. Sorry.

0

That's fine.

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