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

Script not working? Help.

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!

1 comment

0

Code block please!

1 answer

✓ Accepted answer

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)

3 comments

0

Thx! Then what is GetChildren() used for if it can only get the children and do nothing about it?

0

@ManiacRoblox1234 | ":GetChildren()" is very useful for executing the same statements while taking up less lines, such as this.

0

Ahh ok thx !

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