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

assigning a ton of variables confuses the game?

This may be your worst nightmare, but please do help with this. I'm making a menu thingy and it always says that "de1" is a nil value when its not.

 value = script.Parent.CurrentPage.Value
 l = script.Parent.L
 r = script.Parent.R
 mc1 = script.Parent:FindFirstChild("MC1")
 mc2 = script.Parent:FindFirstChild("MC2")
 mc3 = script.Parent:FindFirstChild("MC3")
 mc4 = script.Parent:FindFirstChild("MC4")
 mc5 = script.Parent:FindFirstChild("MC5")
 de1 = script.Parent:FindFirstChild("DE1")
 de2 = script.Parent:FindFirstChild("DE2")
 de3 = script.Parent:FindFirstChild("DE3")
 de4 = script.Parent:FindFirstChild("DE4")
 dr1 = script.Parent:FindFirstChild("DR1")
 dr2 = script.Parent:FindFirstChild("DR2")
 dr3 = script.Parent:FindFirstChild("DR3")
 dr4 = script.Parent:FindFirstChild("DR4")
 dr5 = script.Parent:FindFirstChild("DR5")
 debounce = false
 cooldown = 1
function ChangePage1()
	
	
	if value == 1 then
		debounce = true
		
		print 'value is 1'
		value = 2
		mc1.Visible = false
		mc2.Visible = false
		mc3.Visible = false
		mc4.Visible = false
		mc5.Visible = false
		de1.Visible = true
		de2.Visible = true
		de3.Visible = true
		de4.Visible = true
		
		l.Visible = true
		l.Active = true
		wait(cooldown)
		debounce = false
		
		
	
		
	
	else
	print 'value is 2'
	debounce = true
		value = 3
		de1.Visible = false
		de2.Visible = false
		de3.Visible = false
		de4.Visible = false
		
		dr1.Visible = true
		dr2.Visible = true
		dr3.Visible = true
		dr4.Visible = true
		dr5.Visible = true
		r.Visible = false
		r.Active = false
		wait(cooldown)
		debounce = false
		
		
	end
	
	
	
end

r.MouseButton1Click:Connect(ChangePage1)


function ChangePage2()
	
	if value == 2 then
		debounce = true
		print 'value is 2'
		value = 1
		de1.Visible = false
		de2.Visible = false
		de3.Visible = false
		de4.Visible = false
		
		mc1.Visible = true
		mc2.Visible = true
		mc3.Visible = false
		mc4.Visible = true
		mc5.Visible = true
		l.Visible = false
		l.Active = true
		wait(cooldown)
		debounce = false
		
	else
		debounce = true
		print 'value is 3'
		value = 2
		dr1.Visible = false
		dr2.Visible = false
		dr3.Visible = false
		dr4.Visible = false
		dr5.Visible = false
		de1.Visible = true
		de2.Visible = true
		de3.Visible = true
		de4.Visible = true
		
		r.Visible = true
		r.Active = true
		wait(cooldown)
		debounce = false
		
	end
	
	
	
end

l.MouseButton1Click:Connect(ChangePage2)

thanks!

2 answers

✓ Accepted answer

The ton of variables aren't the problem. It's telling you the child isn't loaded yet or it doesn't exist. Also instead of having a ton of variables with pretty similar names, just use a loop. It's a lot cleaner. Make sure all of the names are correct as well.

1 comment

0

Thanks!

Try using WaitForChild() instead of FindFirstChild().

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