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

Game doesn't Start? :/

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

✓ Accepted answer

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.

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