Skip to content
TheChatArchiveThe Chat Archive
gpt-4o-2024-05-13· OpenAIAi2 WildChat-4.8M (AI2)

local Player = game.Players.LocalPlayer local Character = Player.Character local…

  1. 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
    end
    

    end

    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.

  2. Assistant

    To implement the functionality where the camera switches between different objects like the Head and the Humanoid, you need to modify the FP function within the ExceptionFrames table. Here’s how you can achieve that:

    1. Define the FP Function: Add a simple state management to switch the CameraSubject.
    2. Invoke FP function on Button Click: When the button named FP is 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
    end
    

    Explanation:

    1. State Management:

      • The state variable keeps track of the current state of the CameraSubject.
      • state = (state + 1) % 2 toggles the state between 0 (Head) and 1 (Humanoid).
    2. switchCameraSubject Function:

      • State 0: CameraSubject is switched to the Head of the Character. It checks for the Head part and sets it as the CameraSubject.
      • State 1: CameraSubject is switched to the Humanoid of the Character.
    3. ExceptionFrames:

      • The FP function within ExceptionFrames calls switchCameraSubject() whenever the button named FP is clicked.
    4. Event Listener:

      • It sets up event listeners for all TextButton children of MainFrame, executing onButtonClick when clicked.

    This code enables you to toggle the CameraSubject between the Character's Head and the Humanoid each time the FP button is pressed.