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