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

Get Parts With The Same Name?

Asked by 9 years ago

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

Log in to vote
0
Answered by 9 years ago

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)
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. DeanoMotorsports2001 5 — 9y
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. Darknesschaos 0 — 9y
0
Ok, thank you very much Darknesschaos. DeanoMotorsports2001 5 — 9y
Ad

Answer this question