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

Game doesn't Start? :/

Asked by 9 years ago
wait(3)
startgame()
function startgame()
wait()
local model = game.Lighting.Maps
local map = model:GetChildren()[math.random(1, #model:GetChildren())]
print(map)
startgame()
end

Very simple script but i dont know where i have gone wrong

Output-- 17:06:41.760 - Workspace.Script:2: attempt to call global 'startgame' (a nil value) 17:06:41.762 - Stack Begin 17:06:41.763 - Script 'Workspace.Script', Line 2 17:06:41.763 - Stack End

1 answer

Log in to vote
1
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago

startgame doesn't exist on line 2.

Your script is always read from left to right, top to bottom. You create the function on line 3, but you try to use it on line 2. You can't access something before you create it, that doesn't make sense.

Just call the function after it's created;

wait(3) --startgame doesn't exist here
--Or here
--Or here

function startgame() 
    wait()
    local model = game.Lighting.Maps
    local map = model:GetChildren()[math.random(1, #model:GetChildren())]
    print(map)
    startgame()
end

startgame() --NOW the function exists.
Ad

Answer this question