LandMine = script.Parent
enabled = false
function onTouched(hit) if enabled == false then explosion = Instance.new("Explosion") explosion.BlastRadius = 10 explosion.BlastPressure = 200000 explosion.Position = script.Parent.Position explosion.Parent = Workspace LandMine.Transparency = 1 LandMine.CanCollide = false script.Parent.Parent:GetChildren().Anchored = false enabled = true end end
LandMine.Touched:connect(onTouched)
Everything works fine except for the part whereby when it explodes, it is suppose to un-anchor all the bricks, but it doesn't work when I try it out. (Line 14). Help appreciated. Thanks!
Your error was that you used :GetChildren()
, GetChildren is ONLY used to get the Children, not Modify/Change it, So in the case i'll use the in Pairs
you can learn more about it on this ScriptingHelpers Link: https://scriptinghelpers.org/questions/4036/what-does-in-pairs-do
Here is the script that I fixed:
LandMine=script.Parent enabled = false function onTouched(hit) if enabled == false then local explosion = Instance.new("Explosion", LandMine) explosion.Position=LandMine.Position explosion.BlastRadius = 10 explosion.BlastPressure = 200000 LandMine.CanCollide = false for i,v in pairs(LandMine.Parent:GetChildren()) do--This is what I changed v.Anchored = false end end end LandMine.Touched:connect(onTouched)