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

Get Parts With The Same Name?

I finally got somewhere with making a car explode for my Game, however when I hit any of the 120 bricks (Walls) it won't run the script. Could anybody help me out here?

	debounce = false
	S = script.Parent
	script.Parent.Touched:connect(function(Explode)
		if debounce == true then return end
		debounce = true
		if Explode.Parent.Parent.Parent:FindFirstChild("Wall") then
			S.Fire.Enabled = true
			S.Smoke.Enabled = true
			wait(4)
			S.Parent.Sound:Play()
	e = Instance.new("Explosion")
	e.Parent = S
	e.Position = S.Position
	e.BlastRadius = 10
	e.BlastPressure = 5000000
		S.Fire:Destroy()
		S.Smoke:Destroy()
		S.Parent.VehicleSeat.MaxSpeed = 0
		S.Parent.VehicleSeat.Torque = 0
		S.Parent.VehicleSeat.TurnSpeed = 0
			debounce = false
		end
	end)

1 answer

Okay, I made an edit. See if this works.

debounce = false
S = script.Parent
script.Parent.Touched:connect(function(Explode)
    if debounce == true then return end
    debounce = true
    for i, v in pairs(Explode.Parent.Parent.Parent:GetChildren()) do -- We look for each part within the parent using GetChildren
	if v.Name == "Wall" then -- If it has a name called Wall then..
		S.Fire.Enabled = true
        S.Smoke.Enabled = true
        wait(4)
        S.Parent.Sound:Play()
e = Instance.new("Explosion")
e.Parent = S
e.Position = S.Position
e.BlastRadius = 10
e.BlastPressure = 5000000
    S.Fire:Destroy()
    S.Smoke:Destroy()
    S.Parent.VehicleSeat.MaxSpeed = 0
    S.Parent.VehicleSeat.Torque = 0
    S.Parent.VehicleSeat.TurnSpeed = 0
        debounce = false
	end
end
	end)

3 comments

0

It didn't work, but I appreciate you trying. It seems that it's when there's more than one brick with the same name, only one will work when it gets touched. Thanks again.

0

Oh! Then you should you a for loop to take all the parts within the car. I'll post the script and see if it works.

0

Ok, thank you very much Darknesschaos.

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