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

Does anyone know why it is erroring me every time I try to call this function?

Asked by
CVDev 2
6 years ago

For some reason, it won't run my wallOfDoom() function. It says "21:24:10.453 - ServerScriptService.GameModes:41: attempt to call global 'wallOfDoomDisaster' (a nil value)"

I'm frustrated that it won't run it...

local function meteorsDisaster()
local explosionPart = script.Prefabs.ExplosionPart
local gameRoundLength = 10
local gameInterMissonLength = 10
local roundStartTime 

local function wallOfDoomDisaster()
    local wallOfDoom = script.Prefabs.WallOfDoom
    wallOfDoom.Parent = game.Workspace
end

local function initialize()
    roundStartTime = tick()     

end

local function createExplosionPartCopy()
    local explosionPartCopy = explosionPart:Clone()
    explosionPartCopy.Parent = game.Workspace
    local xPosition = math.random(-64, 79)
    local zPosition = math.random(-45, 90)
    explosionPartCopy.Position = Vector3.new(xPosition, 100, zPosition)
end

while true do
    initialize()

repeat
    local currentTime = tick
    local timeSinceGameStarted = currentTime - roundStartTime
    createExplosionPartCopy()
    wait(.5)
until timeSinceGameStarted > gameRoundLength

wait(gameInterMissonLength)

wallOfDoomDisaster()
end
end

wallOfDoomDisaster()

1 answer

Log in to vote
0
Answered by 6 years ago

If you tabbed everything correctly, the script would look like this:

local function meteorsDisaster()
    local explosionPart = script.Prefabs.ExplosionPart
    local gameRoundLength = 10
    local gameInterMissonLength = 10
    local roundStartTime 

    local function wallOfDoomDisaster()
        local wallOfDoom = script.Prefabs.WallOfDoom
        wallOfDoom.Parent = game.Workspace
    end

    local function initialize()
        roundStartTime = tick()
    end

    local function createExplosionPartCopy()
        local explosionPartCopy = explosionPart:Clone()
        explosionPartCopy.Parent = game.Workspace
        local xPosition = math.random(-64, 79)
        local zPosition = math.random(-45, 90)
        explosionPartCopy.Position = Vector3.new(xPosition, 100, zPosition)
    end

    while true do
        initialize()

        repeat
            local currentTime = tick
            local timeSinceGameStarted = currentTime - roundStartTime
            createExplosionPartCopy()
            wait(.5)
        until timeSinceGameStarted > gameRoundLength

        wait(gameInterMissonLength)

        wallOfDoomDisaster()
    end
end

wallOfDoomDisaster()

Do you see the problem? You declared wallOfDoomDisaster as a local variable to the meteorsDisaster function. Presumably, you never finished it and just put an 'end' at the bottom of the script when the error showed up. Always indenting properly is encouraged to help find errors like this.

You need to move one of the final ends (ex line 39) to line 2. Note that the final call to wallOfDoomDisaster won't run because the while true do loop will never exit, so remove it (or, for testing purposes, move it to before the while true do loop).

0
Plus he never calls meteorsDisaster() so he can't expect the function to execute Pejorem 164 — 6y
0
He did. Also, he can still use recursion. hiimgoodpack 2009 — 6y
Ad

Answer this question