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

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

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

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).

2 comments

0

Plus he never calls meteorsDisaster() so he can't expect the function to execute

0

He did. Also, he can still use recursion.

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