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

How do I get my bomb script to work?

Asked by 10 years ago

I am trying to make a bomb that makes a huge ball which expands and kills all players that touch it. I have tried changing everything yet I don't even get a signal that anything is working

function onTouch()
    if not enabled then
        return
    end
    enabled=false

    bombEffect(bomb)

    kill()

wait(5)
enabled = true
end

script.Parent.Touched:connect(onTouch)


function bombEffect(bomb)
sphere = Instance.new("part")
local mesh = Instance.new("SpecialMesh")
mesh.Meshtype = 3
mesh.Parent = sphere
sphere = Enum.Materials.Metal
sphere.TopSurface = 0
sphere.BottomSurface = 0
sphere.LeftSurface = 0
sphere.RightSurface = 0
sphere = Vector3.new(0, 0, 0)
sphere.CanCollide = false
sphere.Transparency = 0.5
sphere.BrickColor = BrickColor.new(1, 1, 1)
sphere.Parent = game.Workspace
end

function kill()
    children = {}
    recursiveGetChildren(game.Workspace)
    script.Parent:BreakJoints()
end

script.Parent.Touched:connect(kill)


function recursiveGetChildren(parent)

    local kids = parent:GetChildren()

    if kids ~= nil then
        for i =1, #kids do

            table.insert(children,kids[i])
            recursiveGetChildren(kids[i])
        end
    end
end

1 answer

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

1) Logic Error: enabled Check

Your touched event requires enabled to be true; however, enabled is never initially set to true, so it may never start.


2) Suggestion: Scope Concern

Your usage of the variable children in recursiveGetChildren is in this state correct but could easily be broken.

children should be a parameter passed to it. This is because in the current state, this only works when children is a global variable, which on its own is considered bad practice anyway.

Also note that GetChildren() cannot return nil so that check is unnecessary.

function recursiveGetChildren(parent, children)
    local kids = parent:GetChildren()
    for i = 1, #kids do
        table.insert(children,kids[i])
        recursiveGetChildren(kids[i], children)
    end
end

3) Suggestion: Unused Variable

Again, not an error. But your parameter to bombEffect isn't used and should be removed (lines 18 and 7).

Ad

Answer this question