Skip to content
The Chat Archive
gpt-4o-2024-05-13· OpenAI 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 Humanoid = Character.Humanoid local Mouse = Player:GetMouse() local RunService = game:GetService("RunService") local MaxDegree = math.rad(80) local Connection

    local currentCam = 0

    function updatetransparency(targ,bool) for i,v in pairs(targ:GetChildren()) do if v:IsA("Accessory") then updatetransparency(v,bool) elseif v:IsA("BasePart") then --HatAttachment FaceCenterAttachment HairAttachment NeckAttachment if v:FindFirstChild("HatAttachment") or v:FindFirstChild("FaceCenterAttachment") or v:FindFirstChild("FaceFrontAttachment") or v:FindFirstChild("FaceRearAttachment") or v:FindFirstChild("HairAttachment") or v:FindFirstChild("NeckAttachment") then if bool then v.LocalTransparencyModifier = 1 else v.LocalTransparencyModifier = v.Transparency end end end end end

    function updatechartransparency(targ,bool) for i,v in pairs(targ:GetChildren()) do if v:IsA("BasePart") then if bool or v.Name == "Head" then v.LocalTransparencyModifier = 1 else v.LocalTransparencyModifier = v.Transparency end updatetransparency(v,bool) elseif v:IsA("Folder") or v:IsA("Model") then updatetransparency(v,bool) end end end

    local Exceptions = { FP = function() if currentCam == 0 then currentCam += 1 Camera.FieldOfView = 70 Camera.CameraSubject = Character.Head updatetransparency(Player.Character) elseif currentCam == 1 then currentCam += 1 updatetransparency(Player.Character,true) updatechartransparency(Player.Character) Camera.FieldOfView = 90 Connection = RunService.RenderStepped:Connect(function() local np = Vector2.new(Mouse.X, Mouse.Y) local centre = Vector2.new(Camera.ViewportSize.X/2, Camera.ViewportSize.Y/2) local difference = np - centre

    			local outcome = Vector2.new((difference.Y/centre.Y)*MaxDegree, (difference.X/centre.X)*MaxDegree)
    
    			Camera.CFrame = Character.Head.CFrame* CFrame.new(0,0,(-Character.Head.Size.Z/2)*1.25)* CFrame.Angles(-outcome.X, -outcome.Y,0)
    		end)
    	elseif currentCam == 2 then
    		Connection:Disconnect()
    		updatetransparency(Player.Character)
    		currentCam = 0
    		Camera.FieldOfView = 70
    		Camera.CameraSubject = Character.Humanoid
    	end
    
    end,
    ExcludedFrame2 = function()
    end,
    -- if the player presses a button that is not supposed to have a frame,
    -- the code in here will run.
    

    }

    local function onButtonClick(button) if Exceptions[button.Name] then Exceptionsbutton.Name else local targetFrame = MainFrame.Parent:FindFirstChild(button.Name) if targetFrame and targetFrame:IsA("Frame") then targetFrame.Visible = true print("Frame named '" .. targetFrame.Name .. "' is now visible.") else warn("Frame named '" .. targetFrame.Name .. "' not found.") end end end

    updatetransparency and updatechartransparency are very hard to find and i cant understand how do they work. rewrite them in an easier way to understand. don't add comments.

    for _, child in MainFrame:GetChildren() do if child:IsA("TextButton") then child.MouseButton1Click:Connect(function() onButtonClick(child) end) end end

  2. Assistant

    Sure, here are the updatetransparency and updatechartransparency functions rewritten for better readability:

    function setTransparency(target, isTransparent)
    	for _, child in pairs(target:GetChildren()) do
    		if child:IsA("Accessory") then
    			setTransparency(child, isTransparent)
    		elseif child:IsA("BasePart") then
    			local hasAttachment = child:FindFirstChild("HatAttachment") or 
    				child:FindFirstChild("FaceCenterAttachment") or 
    				child:FindFirstChild("FaceFrontAttachment") or
    				child:FindFirstChild("FaceRearAttachment") or 
    				child:FindFirstChild("HairAttachment") or 
    				child:FindFirstChild("NeckAttachment")
    
    			if hasAttachment then
    				child.LocalTransparencyModifier = isTransparent and 1 or child.Transparency
    			end
    		end
    	end
    end
    
    function setCharacterTransparency(character, isTransparent)
    	for _, part in pairs(character:GetChildren()) do
    		if part:IsA("BasePart") then
    			if isTransparent or part.Name == "Head" then
    				part.LocalTransparencyModifier = 1
    			else
    				part.LocalTransparencyModifier = part.Transparency
    			end
    			setTransparency(part, isTransparent)
    		elseif part:IsA("Folder") or part:IsA("Model") then
    			setTransparency(part, isTransparent)
    		end
    	end
    end
    

    This should make the logic easier to follow. The first function, setTransparency, recursively sets the transparency for any accessories or parts that have specific attachments. The second function, setCharacterTransparency, applies this logic to the entire character, ensuring that the Head part is always fully transparent if the isTransparent flag is true.

  3. User

    is there any other meaningful names you can give to these functions?

  4. Assistant

    Yes, I can suggest more descriptive names that convey the purpose of each function more clearly:

    • setTransparency can be renamed to updateAccessoryTransparency to make it clear that this function updates the transparency of accessories or any specific parts within the target.
    • setCharacterTransparency can be renamed to updateCharacterTransparency to indicate that this function updates the transparency of the character's parts.

    Here is the updated code with these new names:

    function updateAccessoryTransparency(target, isTransparent)
    	for _, child in pairs(target:GetChildren()) do
    		if child:IsA("Accessory") then
    			updateAccessoryTransparency(child, isTransparent)
    		elseif child:IsA("BasePart") then
    			local hasRelevantAttachment = child:FindFirstChild("HatAttachment") or 
    				child:FindFirstChild("FaceCenterAttachment") or 
    				child:FindFirstChild("FaceFrontAttachment") or
    				child:FindFirstChild("FaceRearAttachment") or 
    				child:FindFirstChild("HairAttachment") or 
    				child:FindFirstChild("NeckAttachment")
    
    			if hasRelevantAttachment then
    				child.LocalTransparencyModifier = isTransparent and 1 or child.Transparency
    			end
    		end
    	end
    end
    
    function updateCharacterTransparency(character, isTransparent)
    	for _, part in pairs(character:GetChildren()) do
    		if part:IsA("BasePart") then
    			if isTransparent or part.Name == "Head" then
    				part.LocalTransparencyModifier = 1
    			else
    				part.LocalTransparencyModifier = part.Transparency
    			end
    			updateAccessoryTransparency(part, isTransparent)
    		elseif part:IsA("Folder") or part:IsA("Model") then
    			updateAccessoryTransparency(part, isTransparent)
    		end
    	end
    end
    

    These new names should provide a clearer understanding of what each function does and improve the readability of the code.

  5. User

    local Player = game.Players.LocalPlayer local Character = Player.Character local MainFrame = script.Parent local Camera = workspace.CurrentCamera local Humanoid = Character.Humanoid local Mouse = Player:GetMouse() local RunService = game:GetService("RunService") local MaxDegree = math.rad(80) local Connection

    local currentCam = 0

    function updatetransparency(targ,bool) for i,v in pairs(targ:GetChildren()) do if v:IsA("Accessory") then updatetransparency(v,bool) elseif v:IsA("BasePart") then --HatAttachment FaceCenterAttachment HairAttachment NeckAttachment if v:FindFirstChild("HatAttachment") or v:FindFirstChild("FaceCenterAttachment") or v:FindFirstChild("FaceFrontAttachment") or v:FindFirstChild("FaceRearAttachment") or v:FindFirstChild("HairAttachment") or v:FindFirstChild("NeckAttachment") then if bool then v.LocalTransparencyModifier = 1 else v.LocalTransparencyModifier = v.Transparency end end end end end

    function updatechartransparency(targ,bool) for i,v in pairs(targ:GetChildren()) do if v:IsA("BasePart") then if bool or v.Name == "Head" then v.LocalTransparencyModifier = 1 else v.LocalTransparencyModifier = v.Transparency end updatetransparency(v,bool) elseif v:IsA("Folder") or v:IsA("Model") then updatetransparency(v,bool) end end end

    local Exceptions = { FP = function() if currentCam == 0 then currentCam += 1 Camera.FieldOfView = 70 Camera.CameraSubject = Character.Head updatetransparency(Player.Character) elseif currentCam == 1 then currentCam += 1 updatetransparency(Player.Character,true) updatechartransparency(Player.Character) Camera.FieldOfView = 90 Connection = RunService.RenderStepped:Connect(function() local np = Vector2.new(Mouse.X, Mouse.Y) local centre = Vector2.new(Camera.ViewportSize.X/2, Camera.ViewportSize.Y/2) local difference = np - centre

    			local outcome = Vector2.new((difference.Y/centre.Y)*MaxDegree, (difference.X/centre.X)*MaxDegree)
    
    			Camera.CFrame = Character.Head.CFrame* CFrame.new(0,0,(-Character.Head.Size.Z/2)*1.25)* CFrame.Angles(-outcome.X, -outcome.Y,0)
    		end)
    	elseif currentCam == 2 then
    		Connection:Disconnect()
    		updatetransparency(Player.Character)
    		currentCam = 0
    		Camera.FieldOfView = 70
    		Camera.CameraSubject = Character.Humanoid
    	end
    
    end,
    ExcludedFrame2 = function()
    end,
    -- if the player presses a button that is not supposed to have a frame,
    -- the code in here will run.
    

    }

    local function onButtonClick(button) if Exceptions[button.Name] then Exceptionsbutton.Name else local targetFrame = MainFrame.Parent:FindFirstChild(button.Name) if targetFrame and targetFrame:IsA("Frame") then targetFrame.Visible = true print("Frame named '" .. targetFrame.Name .. "' is now visible.") else warn("Frame named '" .. targetFrame.Name .. "' 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

    now rewrite this code.

  6. Assistant

    Certainly! Below is the rewritten version of your code with improved readability and consistent naming for functions. I've also utilized the more descriptive function names suggested earlier.

    local Player = game.Players.LocalPlayer
    local Character = Player.Character
    local MainFrame = script.Parent
    local Camera = workspace.CurrentCamera
    local Humanoid = Character:WaitForChild("Humanoid")
    local Mouse = Player:GetMouse()
    local RunService = game:GetService("RunService")
    local MaxDegree = math.rad(80)
    
    local currentCam = 0
    local connection
    
    local function updateAccessoryTransparency(target, isTransparent)
    	for _, child in pairs(target:GetChildren()) do
    		if child:IsA("Accessory") then
    			updateAccessoryTransparency(child, isTransparent)
    		elseif child:IsA("BasePart") then
    			local hasRelevantAttachment = child:FindFirstChild("HatAttachment") or 
    				child:FindFirstChild("FaceCenterAttachment") or 
    				child:FindFirstChild("FaceFrontAttachment") or
    				child:FindFirstChild("FaceRearAttachment") or 
    				child:FindFirstChild("HairAttachment") or 
    				child:FindFirstChild("NeckAttachment")
    
    			if hasRelevantAttachment then
    				child.LocalTransparencyModifier = isTransparent and 1 or child.Transparency
    			end
    		end
    	end
    end
    
    local function updateCharacterTransparency(character, isTransparent)
    	for _, part in pairs(character:GetChildren()) do
    		if part:IsA("BasePart") then
    			if isTransparent or part.Name == "Head" then
    				part.LocalTransparencyModifier = 1
    			else
    				part.LocalTransparencyModifier = part.Transparency
    			end
    			updateAccessoryTransparency(part, isTransparent)
    		elseif part:IsA("Folder") or part:IsA("Model") then
    			updateAccessoryTransparency(part, isTransparent)
    		end
    	end
    end
    
    local Exceptions = {
    	FP = function()
    		if currentCam == 0 then
    			currentCam += 1
    			Camera.FieldOfView = 70
    			Camera.CameraSubject = Character:FindFirstChild("Head")
    			updateAccessoryTransparency(Character)
    		elseif currentCam == 1 then
    			currentCam += 1
    			updateAccessoryTransparency(Character, true)
    			updateCharacterTransparency(Character)
    			Camera.FieldOfView = 90
    			connection = RunService.RenderStepped:Connect(function()
    				local mousePos = Vector2.new(Mouse.X, Mouse.Y)
    				local screenCenter = Camera.ViewportSize / 2
    				local delta = mousePos - screenCenter
    
    				local angle = Vector2.new((delta.Y / screenCenter.Y) * MaxDegree, (delta.X / screenCenter.X) * MaxDegree)
    				Camera.CFrame = Character.Head.CFrame * CFrame.new(0, 0, (-Character.Head.Size.Z / 2) * 1.25) * CFrame.Angles(-angle.X, -angle.Y, 0)
    			end)
    		elseif currentCam == 2 then
    			connection:Disconnect()
    			updateAccessoryTransparency(Character)
    			currentCam = 0
    			Camera.FieldOfView = 70
    			Camera.CameraSubject = Humanoid
    		end
    	end,
    	ExcludedFrame2 = function() 
    		-- Handle any specific functionality for another frame
    	end,
    }
    
    local function onButtonClick(button)
    	if Exceptions[button.Name] then
    		Exceptions[button.Name]()	
    	else
    		local targetFrame = MainFrame.Parent:FindFirstChild(button.Name)
    		if targetFrame and targetFrame:IsA("Frame") then
    			targetFrame.Visible = true
    			print("Frame named '" .. targetFrame.Name .. "' is now visible.")
    		else
    			warn("Frame named '" .. targetFrame.Name .. "' not found.")
    		end
    	end
    end
    
    for _, child in pairs(MainFrame:GetChildren()) do
    	if child:IsA("TextButton") then
    		child.MouseButton1Click:Connect(function()
    			onButtonClick(child)
    		end)
    	end
    end
    

    This version aims to maintain the same functionality as your original script while being easier to read and understand. The functions have been renamed for clarity and the logic is slightly restructured to improve readability.