local Players = game:GetService("Players") local UserInputService = game:GetService("UserInputService") local player = Players.LocalPlayer -- Default keybind for hiding the GUI local hideKey = Enum.KeyCode.F1 -- Function to create the GUI local function createGUI() -- Destroy existing GUI if it exists local existingGui = player.PlayerGui:FindFirstChild("HealthCapGUI") if existingGui then existingGui:Destroy() end -- Create the new GUI local screenGui = Instance.new("ScreenGui") screenGui.Name = "HealthCapGUI" screenGui.Parent = player:WaitForChild("PlayerGui") local frame = Instance.new("Frame") frame.Size = UDim2.new(0, 200, 0, 150) frame.Position = UDim2.new(0.5, -100, 0.5, -75) frame.BackgroundColor3 = Color3.new(0.2, 0.2, 0.2) frame.BorderSizePixel = 2 frame.Parent = screenGui frame.Active = true frame.Draggable = true -- Make the frame draggable local healthLabel = Instance.new("TextLabel") healthLabel.Size = UDim2.new(1, 0, 0.3, 0) healthLabel.Position = UDim2.new(0, 0, 0, 0) healthLabel.Text = "Set Max Health:" healthLabel.TextColor3 = Color3.new(1, 1, 1) healthLabel.BackgroundColor3 = Color3.new(0.3, 0.3, 0.3) healthLabel.Parent = frame local healthInput = Instance.new("TextBox") healthInput.Size = UDim2.new(1, 0, 0.3, 0) healthInput.Position = UDim2.new(0, 0, 0.3, 0) healthInput.PlaceholderText = "Enter max health value" healthInput.Text = "" healthInput.BackgroundColor3 = Color3.new(0.3, 0.3, 0.3) healthInput.TextColor3 = Color3.new(1, 1, 1) healthInput.Parent = frame local setHealthButton = Instance.new("TextButton") setHealthButton.Size = UDim2.new(1, 0, 0.2, 0) setHealthButton.Position = UDim2.new(0, 0, 0.6, 0) setHealthButton.Text = "Set Max Health" setHealthButton.BackgroundColor3 = Color3.new(0.3, 0.3, 0.3) setHealthButton.TextColor3 = Color3.new(1, 1, 1) setHealthButton.Parent = frame local closeButton = Instance.new("TextButton") closeButton.Size = UDim2.new(1, 0, 0.2, 0) closeButton.Position = UDim2.new(0, 0, 0.8, 0) closeButton.Text = "Close" closeButton.BackgroundColor3 = Color3.new(0.3, 0.3, 0.3) closeButton.TextColor3 = Color3.new(1, 1, 1) closeButton.Parent = frame -- Handle setting max health setHealthButton.MouseButton1Click:Connect(function() local maxHealthValue = tonumber(healthInput.Text) if maxHealthValue and maxHealthValue > 0 then local character = player.Character or player.CharacterAdded:Wait() local humanoid = character:FindFirstChildOfClass("Humanoid") if humanoid then humanoid.MaxHealth = maxHealthValue -- Set the maximum health humanoid.Health = maxHealthValue -- Adjust current health to match the new max else warn("Humanoid not found in character.") end else warn("Please enter a valid max health value.") end end) -- Handle closing the GUI closeButton.MouseButton1Click:Connect(function() screenGui:Destroy() end) end -- Hide/Show GUI functionality local function toggleGUIVisibility() local screenGui = player.PlayerGui:FindFirstChild("HealthCapGUI") if screenGui then screenGui.Enabled = not screenGui.Enabled end end -- Change the hide key local function changeHideKey(newKey) hideKey = newKey end -- Handle key presses for hiding GUI UserInputService.InputBegan:Connect(function(input, gameProcessed) if not gameProcessed and input.KeyCode == hideKey then toggleGUIVisibility() end end) -- Ensure GUI persists after respawn local function onCharacterAdded() createGUI() end -- Listen for character respawns player.CharacterAdded:Connect(onCharacterAdded) -- Create the GUI when the script runs if player.Character then createGUI() else player.CharacterAdded:Wait() createGUI() end -- Allow changing the hide key (for demonstration) -- Example: Call `changeHideKey(Enum.KeyCode.F2)` to change the hide key to F2.