local Player = game.Players.LocalPlayer local Character = Player.Character local…
- User
local Player = game.Players.LocalPlayer local Character = Player.Character local MainFrame = script.Parent local Camera = workspace.CurrentCamera
local ExceptionFrames = { FP = function() --TODO: implement camera end, ExcludedFrame2 = function() end, }
local function onButtonClick(button) local frameName = button.Name
if ExceptionFrames[frameName] then ExceptionFrames[frameName]() else local targetFrame = MainFrame.Parent:FindFirstChild(frameName) if targetFrame and targetFrame:IsA("Frame") then targetFrame.Visible = true print("Frame named '" .. frameName .. "' is now visible.") else warn("Frame named '" .. frameName .. "' not found.") end endend
for _, child in (MainFrame:GetChildren()) do if child:IsA("TextButton") then child.MouseButton1Click:Connect(function() onButtonClick(child) end) end end
first time FP runs, have the camerasubject switch to the head. then have it switch to the humanoid and so on.
- Assistant
To implement the functionality where the camera switches between different objects like the Head and the Humanoid, you need to modify the
FPfunction within theExceptionFramestable. Here’s how you can achieve that:- Define the FP Function: Add a simple state management to switch the CameraSubject.
- Invoke FP function on Button Click: When the button named
FPis clicked, it should trigger these camera changes.
Here’s the updated code:
local Player = game.Players.LocalPlayer local Character = Player.Character local MainFrame = script.Parent local Camera = workspace.CurrentCamera local state = 0 local function switchCameraSubject() state = (state + 1) % 2 -- This will toggle between 0 (Head) and 1 (Humanoid) if state == 0 then local head = Character:FindFirstChild("Head") or Character:FindFirstChildOfClass("Part") -- Fall back if Head not found if head then Camera.CameraSubject = head print("CameraSubject switched to Head.") else warn("Head not found in Character.") end elseif state == 1 then local humanoid = Character:FindFirstChildOfClass("Humanoid") if humanoid then Camera.CameraSubject = humanoid print("CameraSubject switched to Humanoid.") else warn("Humanoid not found in Character.") end end end local ExceptionFrames = { FP = function() switchCameraSubject() end, ExcludedFrame2 = function() -- Implement other cases as needed end, } local function onButtonClick(button) local frameName = button.Name if ExceptionFrames[frameName] then ExceptionFrames[frameName]() else local targetFrame = MainFrame.Parent:FindFirstChild(frameName) if targetFrame and targetFrame:IsA("Frame") then targetFrame.Visible = true print("Frame named '" .. frameName .. "' is now visible.") else warn("Frame named '" .. frameName .. "' not found.") end end end for _, child in (MainFrame:GetChildren()) do if child:IsA("TextButton") then child.MouseButton1Click:Connect(function() onButtonClick(child) end) end endExplanation:
-
State Management:
- The
statevariable keeps track of the current state of the CameraSubject. state = (state + 1) % 2toggles the state between0(Head) and1(Humanoid).
- The
-
switchCameraSubjectFunction:- State 0: CameraSubject is switched to the Head of the Character. It checks for the
Headpart and sets it as the CameraSubject. - State 1: CameraSubject is switched to the Humanoid of the Character.
- State 0: CameraSubject is switched to the Head of the Character. It checks for the
-
ExceptionFrames:
- The
FPfunction withinExceptionFramescallsswitchCameraSubject()whenever the button namedFPis clicked.
- The
-
Event Listener:
- It sets up event listeners for all
TextButtonchildren ofMainFrame, executingonButtonClickwhen clicked.
- It sets up event listeners for all
This code enables you to toggle the CameraSubject between the Character's Head and the Humanoid each time the
FPbutton is pressed.