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

attempt to call a nil value?

it gives me attemot to call a nil value as i press any button, i have no idea why. no line errors eithr


--declare variables
	local OnlineButton = script.Parent.Frame.OnlineButton
	local StoryButton = script.Parent.Frame.StoryButton
	local RandomModeButton = script.Parent.Frame.RandomModeButton
	local Console = script.Parent.Frame.Console
	local ChosenMode = "Unknown"
	local clearToLoad = true
	local randomMode = math.random(0,1)
-- variables for check	
	local check0 = true
	local check1 = false

-- initialize components
 function render()
	clearToLoad = true
	Console.TextScaled = true
	clear(Console)
	init()
end

function clear(text)
	text.Text = ""
end

 function loadGame()
	Console.Text = "No errors yet! :D"
	Console.Text = Console.Text .. '\nPlease wait at least 5 seconds for loading \nbefore clicking a button.'
	if (OnlineButton == script.Parent.Frame.OnlineButton) then
	elseif (check0 == false) then
		check0 = true
		check()
	else 
		clear(Console)
		Console.Text = Console.Text .. "error! unhandeled exception: code 01 - StartupLogic \n"
	end
	render()
end

function check()
	if (StoryButton == script.Parent.Frame.StoryButton) then
	elseif (check1 == false) then
		check1 = true
		render()
	else
		clear(Console) 
		Console.Text = Console.Text .. "error! unhandled exception: code 02 - StartupLogic \n"
	end
	
end

function PlayGame(mode, allowAccess, isRandom)
	print'connect'
	if (mode == "story") then
	elseif (game.Workspace.StoryActive == true) then
		ChosenMode = "story" 
		Console.Text = Console.Text .. 'Loading Story Mode... \n'
		wait(5)
		clear(Console)
	else
		Console.Text = Console.Text .. 'error! code 03 - StartupLogic \n"storymode not found"'
	end
	if (mode == "online") then
	elseif (game.Workspace.OnlineAvaliable == true) then
		ChosenMode = "online"
		Console.Text = Console.Text .. 'Loading Ejected Online... \n'
		wait(6.5)
		clear(Console)
	else
		Console.Text = Console.Text .. 'error! code 04 -StartupLogic \nOnline servers unavaliable'
	end
	if (mode == "random") then 
	elseif (isRandom == true) then
	elseif (allowAccess == true) then
	elseif (randomMode == 0) then 
		PlayGame("online", true, false)
	elseif (randomMode == 1) then
		PlayGame("story", true, false)
	else
		Console.Text = Console.Text .. "error! code 05 - StartupLogic \nUnknown mode"
		wait(8.5)
		clear(Console)
	end
	clear(Console)
end

function noLoadPermissions(Perm)
	if (Perm == false) then
		Console.Text = Console.Text .. '\nUnable to load! error code 06, something is \n unable to confirm! Contact AlienMister! \n'
		wait(8.5)
		clear(Console)
		loadGame()
	end
end
	
function init()

end
--Now for the code and calling these functions
print 'start'
loadGame()
OnlineButton.MouseButton1Click:connect(PlayGame("online", true, false))
	StoryButton.MouseButton1Click:connect(PlayGame("story", true, false))
	RandomModeButton.MouseButton1Click:connect(PlayGame("random", true, true))


3 comments

2

It would certainly help if you told us what line the error was on, indicated by the output.

2

Remember you can't call functions that were not previously declared. Put the clear function above the render function.

0

yes but it doesnt give me a line number

2 answers

✓ Accepted answer

In the past, this unhelpful error (coupled with having no line number) indicated that you were passing nil to a :connect.

This definitely would happen on line 101, 102, 103:

You want to give :connect the name of a function, so that it knows how to call it repeatedly. When you give it the call of a function, all it knows is what the function returned (which is nothing).

You could define functions PlayOnline, PlayStory, PlayRandom instead. It almost looks like this would make more sense since your PlayGame just decides which set of things needs to be done.

Or, you can use an anonymous function that do this for you:

OnlineButton.MouseButton1Click:connect(function() PlayGame("online", true, false) end)
StoryButton.MouseButton1Click:connect(function() PlayGame("story", true, false) end)
RandomModeButton.MouseButton1Click:connect(function() PlayGame("random", true, true) end)

2 comments

0

k, and could you see my other post cuz i think thatll work too

0

OMG THANK YOU SOO MUCH

ps i also added in prints in random areas, no matter what though, i still get the same error, i know that it does not get passed through loadgame and it goes strait to playgame even if i havent clicked a button. AND I did put render on top now but same thing.

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