Although, everything is working following this code:
--[[
@TwinPlayzDev
--]]
--[[ LOCALS ]]--
local CloseButton = script.Parent.Frame.Frame:WaitForChild("CloseButton")
local NextButton = script.Parent.Frame.Frame:WaitForChild("NextButton")
local BackButton = script.Parent.Frame.Frame:WaitForChild("BackButton")
local Menus = game.Workspace:WaitForChild("Menus")
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local currentCameraIndex = 1
local cameraList = {}
local touchPart = Menus.MenuArea1:WaitForChild("TouchPart")
local menuGui = script.Parent.Frame
local Camera = workspace.CurrentCamera
-- Populate cameraList with cameras and set them inactive
for i = 1, 3 do
cameraList[i] = Menus.MenuArea1:WaitForChild("Camera" .. i)
end
-- Function to switch between cameras
local function switchCamera(direction)
currentCameraIndex = currentCameraIndex + direction
if currentCameraIndex > #cameraList then
currentCameraIndex = 1
elseif currentCameraIndex < 1 then
currentCameraIndex = #cameraList
end
Camera.CFrame = cameraList[currentCameraIndex].CFrame
end
-- Button events
CloseButton.MouseButton1Click:Connect(function()
if CloseButton.Text == "Open Menu" then
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = cameraList[currentCameraIndex].CFrame
CloseButton.Text = "Close Menu"
elseif CloseButton.Text == "Close Menu" then
Camera.CameraType = Enum.CameraType.Custom
Player.CameraMode = Enum.CameraMode.Classic
CloseButton.Text = "Open Menu"
end
end)
NextButton.MouseButton1Click:Connect(function()
switchCamera(1)
end)
BackButton.MouseButton1Click:Connect(function()
switchCamera(-1)
end)
-- Set up touch part events
touchPart.Touched:Connect(function(hit)
local character = hit.Parent
if character and character:IsA("Model") and character:FindFirstChild("Humanoid") and Humanoid.Health > 0 then
menuGui.Visible = true
end
end)
-- Reset camera and menu visibility when player leaves the part
touchPart.TouchEnded:Connect(function(hit)
local character = hit.Parent
if character and character:IsA("Model") and character:FindFirstChild("Humanoid") then
menuGui.Visible = false
end
end)
One of my main issues, is being able to create MORE Menu lists, but using the Same UI/Script. So I had the hierarchy in Workspace of:
Inside of course:
So I’m a little curious… I tried asking ChatGPT 100 times, but how can I possibly make a Table or a ForLoop, to check inside WHICH area they’re in, so whether that’s MenuArea1, or MenuArea2, then finding that TouchPart and those Specific Cameras, then place the CFrame on that.
In Which, I already solved, but am having troubles with having multiple areas.
With multiple areas you can use collectionservice and add a tag for each folder and do :GetDescendants/:GetChildren don’t know whether you want to check the player or part but you can parent either the player’s character/part to the menu areas and check that through looping.
Edit: just do :GetDescendants on the Menus folder
--[[
@TwinPlayzDev
--]]
--[[ LOCALS ]]--
local CloseButton = script.Parent.Frame.Frame:WaitForChild("CloseButton")
local NextButton = script.Parent.Frame.Frame:WaitForChild("NextButton")
local BackButton = script.Parent.Frame.Frame:WaitForChild("BackButton")
local Menus = game.Workspace:WaitForChild("Menus")
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local currentCameraIndex = {}
local cameraList = {}
local touchPartList = {}
local menuGuiList = {}
local Camera = workspace.CurrentCamera
-- Function to switch between cameras
local function switchCamera(menuAreaIndex, direction)
currentCameraIndex[menuAreaIndex] = currentCameraIndex[menuAreaIndex] + direction
if currentCameraIndex[menuAreaIndex] > #cameraList[menuAreaIndex] then
currentCameraIndex[menuAreaIndex] = 1
elseif currentCameraIndex[menuAreaIndex] < 1 then
currentCameraIndex[menuAreaIndex] = #cameraList[menuAreaIndex]
end
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = cameraList[menuAreaIndex][currentCameraIndex[menuAreaIndex]].CFrame
end
-- Set up touch part events for each menu area
for _, menuArea in ipairs(Menus:GetChildren()) do
if menuArea:IsA("Folder") then
local touchPart = menuArea:WaitForChild("TouchPart")
local menuGui = script.Parent.Frame
local cameras = {}
for i = 1, 3 do
cameras[i] = menuArea:WaitForChild("Camera" .. i)
end
local index = tonumber(string.match(menuArea.Name, "%d+"))
currentCameraIndex[index] = 1
cameraList[index] = cameras
touchPartList[index] = touchPart
menuGuiList[index] = menuGui
-- Button events
CloseButton.MouseButton1Click:Connect(function()
if CloseButton.Text == "Open Menu" then
CloseButton.Text = "Close Menu"
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = cameraList[index][currentCameraIndex[index]].CFrame
else
Camera.CameraType = Enum.CameraType.Custom
Player.CameraMode = Enum.CameraMode.Classic
CloseButton.Text = "Open Menu"
end
end)
NextButton.MouseButton1Click:Connect(function()
switchCamera(index, 1)
end)
BackButton.MouseButton1Click:Connect(function()
switchCamera(index, -1)
end)
-- Set up touch part events
touchPart.Touched:Connect(function(hit)
local character = hit.Parent
if character and character:IsA("Model") and character:FindFirstChild("Humanoid") and Humanoid.Health > 0 then
menuGui.Visible = true
end
end)
-- Reset camera and menu visibility when player leaves the part
touchPart.TouchEnded:Connect(function(hit)
local character = hit.Parent
if character and character:IsA("Model") and character:FindFirstChild("Humanoid") then
menuGui.Visible = false
end
end)
end
end
I got this to work, although, I’m having issues with the CurrentCamera being set to the player FIRST instead of going to the board right away:
--[[
@TwinPlayzDev
--]]
--[[ LOCALS ]]--
local CloseButton = script.Parent.Frame.Frame:WaitForChild("CloseButton")
local NextButton = script.Parent.Frame.Frame:WaitForChild("NextButton")
local BackButton = script.Parent.Frame.Frame:WaitForChild("BackButton")
local Menus = game.Workspace:WaitForChild("Menus")
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local currentCameraIndex = {}
local cameraList = {}
local touchPartList = {}
local menuGuiList = {}
local Camera = workspace.CurrentCamera
local debounce = false
--[[ FUNCTIONS ]]--
local function switchCamera(menuAreaIndex, direction)
currentCameraIndex[menuAreaIndex] = currentCameraIndex[menuAreaIndex] + direction
if currentCameraIndex[menuAreaIndex] > #cameraList[menuAreaIndex] then
currentCameraIndex[menuAreaIndex] = 1
elseif currentCameraIndex[menuAreaIndex] < 1 then
currentCameraIndex[menuAreaIndex] = #cameraList[menuAreaIndex]
end
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = cameraList[menuAreaIndex][currentCameraIndex[menuAreaIndex]].CFrame
end
local function Enable()
debounce = true
CloseButton.Text = "Close Menu"
end
local function Disable()
debounce = false
CloseButton.Text = "Open Menu"
end
--[[ FOR LOOP ]]--
for _, menuArea in ipairs(Menus:GetChildren()) do
if menuArea:IsA("Folder") then
local touchPart = menuArea:WaitForChild("TouchPart")
local menuGui = script.Parent.Frame
local cameras = {}
for i = 1, 3 do
cameras[i] = menuArea:WaitForChild("Camera" .. i)
end
local index = tonumber(string.match(menuArea.Name, "%d+"))
currentCameraIndex[index] = 1
cameraList[index] = cameras
touchPartList[index] = touchPart
menuGuiList[index] = menuGui
-- Button events
CloseButton.MouseButton1Click:Connect(function()
if debounce == true then
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = cameraList[index][currentCameraIndex[index]].CFrame
else
Camera.CameraType = Enum.CameraType.Custom
Player.CameraMode = Enum.CameraMode.Classic
end
end)
NextButton.MouseButton1Click:Connect(function()
switchCamera(index, 1)
end)
BackButton.MouseButton1Click:Connect(function()
switchCamera(index, -1)
end)
-- Set up touch part events
touchPart.Touched:Connect(function(hit)
local character = hit.Parent
if character and character:IsA("Model") and character:FindFirstChild("Humanoid") and Humanoid.Health > 0 then
menuGui.Visible = true
end
end)
-- Reset camera and menu visibility when player leaves the part
touchPart.TouchEnded:Connect(function(hit)
local character = hit.Parent
if character and character:IsA("Model") and character:FindFirstChild("Humanoid") then
menuGui.Visible = false
end
end)
end
end
CloseButton.MouseButton1Click:Connect(function()
if debounce == true then
Disable()
else
Enable()
end
end)
Got it to work, had to be because of the For Loop and Closebutton function I think. Lol, W.
Edit: It’s randomly choosing other menus, it’s not sticking with that dedicated menu. What is wrong?