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

Keep getting a "attempt to call a nil value" in my output?

I keep getting an "attempt to call a nil value" in my output every time I click on a button, here's my scripts.

local clickDetector = script.Parent.ClickDetector
 
if script.Parent.Parent.Name == ("Can I get a burrito?") then
	function onMouseClick()
		script.Parent.Parent.Name = ("Thank you!")
	end
end

clickDetector.MouseClick:connect(onMouseClick)

Note that the first script is the same for every name text

while true do
	creativlyNamedVariable = math.random (1, 4)
	if creativlyNamedVariable == 1 then
		script.Parent.Name = ("Can I get a taco?")
	elseif creativlyNamedVariable == 2 then
		script.Parent.Name = ("Can I get some nachos?")
	elseif creativlyNamedVariable == 3 then
		script.Parent.Name = ("Can I get a burrito?")
	elseif creativlyNamedVariable == 4 then
		script.Parent.Name = ("Can I get a soda?")
		if script.Parent.Name == ("Thank you!") then
			wait(30.8)
			creativlyNamedBye = math.random (1, 3)
			if creativlyNamedBye == 1 then
				script.Parent.Name = ("Bye!")
			elseif creativlyNamedBye == 2 then
				script.Parent.Name = ("Cya!")
			elseif creativlyNamedBye == 3 then
				script.Parent.Name =("Alright, have a good one!")
			end
		end
	end
	wait(35.8)
end 

EDIT: So I just tested it again. But it works with some buttons one time, and then others when I test it another time.

2 comments

0

what line?

0

No idea, just sometimes when I click on the button it will say "attempt to call a nil value". Don't know why at all. I did try to add variables, but that didn't help. sadly :(

1 answer

Well I found it out

local clickDetector = script.Parent.ClickDetector

function onMouseClick()
	if script.Parent.Parent.Name == ("Can I get a burrito?") then
		script.Parent.Parent.Name = ("Thank you!")
	end
end

clickDetector.MouseClick:connect(onMouseClick)

Just needed to put line 3 into the function. Now it works every time!

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