Way to find if a frame doesn't exist


I’m running into an error with my navigation part of my code.

I want to display an error page if a page doesn’t exist, but I’m running into an error while doing that.

local mainNav = script.Parent.Main.bottom
local expandedNav = script.Parent.Main.expanded
local menuDB = false
for i, v in ipairs(mainNav.buttons:GetChildren()) do
	local frame = string.sub(v.Name, 2,100)
		script.Parent.Main[tostring(last)].Visible = false
		last = frame
		script.Parent.Main[frame].Visible = true --The error is here for the "missing" frame
		if not script.Parent.Main[tostring(last)] or script.Parent.Main[frame] then --Doesn't exist
			last = "Other"
			script.Parent.Main.Other.Visible = true
		--		print('"uwu" 🤓')
	--	print('"owo" 🤓')

Thanks for any help!

if frame then
    --// There is a frame
    return; --// There is no frame

you can even run it like

if not frame then return; end

Nevermind, I see what you mean.

That isn’t working.

What might be causing the issue is you had an elseif I would just test it with an else

else isn’t working either

add a bunch of prints and see where exactly it fails
print out v.Name, print out frame, think of it print it out and see where it fails

It’s failing because frame does exist, it’s just a string with the button name. so it continues, to not find the frame and then errors

would the frame name be the exact same as v.Name

It’s v.Name missing a character, because I’m listing the button names

AHome → Home

if locationOfFrame:FindFirstChild(frame) then

This is because frame is just a string such as “Home” so roblox is confused, we need to first search where the frame will be for the frame itself THEN if it finds it do what you need to do

1 Like