Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Script not working? Help.

Asked by 9 years ago

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!

0
Code block please! woodengop 1134 — 9y

1 answer

Log in to vote
0
Answered by
woodengop 1134 Moderation Voter
9 years ago

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)
0
Thx! Then what is GetChildren() used for if it can only get the children and do nothing about it? ManiacRoblox1234 0 — 9y
0
@ManiacRoblox1234 | ":GetChildren()" is very useful for executing the same statements while taking up less lines, such as this. Redbullusa 1580 — 9y
0
Ahh ok thx ! ManiacRoblox1234 0 — 9y
Ad

Answer this question