hello all, Im trying to make this gui helper for myself and I’m trying to use attributes to locate a menu in a table just to make it easier, but I can’t seem to find it. is there an easier way I could go about make it super easy for myself to make a UI that opens up menus
for i,menu in pairs(menus:GetChildren()) do
local menu = tostring(menu)
table.insert(menuList,menu)
print("inserted into table")
end
local function directButton()
print("connected")
print(direction)
local tableloc = table.find(menuList,direction)
print(tableloc)
menuList[tableloc].Visible = true
end
Full script? Where is direction defined? Why are you making a new variable with the same name as the menu in the for loop which is already defined? Why not just do menu.Name instead of tostring(menu)?
I was just trying new things out because I kept getting the error attempt to index nil. direction is defined as a string, which is inside the buttons gui. I’m just trying to make a simple system for myself to use in other games to make a ui.
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local playerUI = script.Parent
local menuUI = playerUI:WaitForChild("menuTest")
local menus = playerUI:WaitForChild("menus")
local direction
local menuList = {}
for i,menu in pairs(menus:GetChildren()) do
local menu = tostring(menu)
table.insert(menuList,menu)
print("inserted into table")
end
local function directButton()
print("connected")
print(direction)
local tableloc = table.find(menuList,direction)
print(tableloc)
menuList[tableloc].Visible = true
end
local function checkForButtons(checkUI)
for i,uiObject in pairs(checkUI:GetChildren()) do
if uiObject:IsA("ImageButton") or uiObject:IsA("TextButton") then
direction = uiObject:GetAttribute("menuDirect")
uiObject.MouseButton1Click:Connect(directButton)
else
checkForButtons(uiObject)
local test
end
end
end
checkForButtons(menuUI)
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local playerUI = script.Parent
local menuUI = playerUI:WaitForChild("menuTest")
local menus = playerUI:WaitForChild("menus")
local menuList = {}
for i,menu in pairs(menus:GetChildren()) do
table.insert(menuList,menu.Name)
print("inserted into table")
end
local function directButton(direction)
print("connected")
print(direction)
local tableloc = table.find(menuList,direction)
print(tableloc)
menuList[tableloc].Visible = true
end
local function checkForButtons(checkUI)
for i,uiObject in pairs(checkUI:GetChildren()) do
if uiObject:IsA("ImageButton") or uiObject:IsA("TextButton") then
uiObject.MouseButton1Click:Connect(function()
directButton(uiObject:GetAttribute("menuDirect")
end)
else
checkForButtons(uiObject)
local test
end
end
end
checkForButtons(menuUI)
Why not store the instances and roll out your own findMenu() function.
for i,menu in pairs(menus:GetChildren()) do
table.insert(menuList,menu)
end
local function directButton()
local menu = findMenu(direction)
menu.Visible = true
end