Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Create a ScreenGui for the buttons
- local gui = Instance.new("ScreenGui")
- gui.Parent = game.Players.LocalPlayer:WaitForChild("PlayerGui")
- -- Create a TextButton for aiming
- local aimButton = Instance.new("TextButton")
- aimButton.Text = "Aim"
- aimButton.Size = UDim2.new(0, 60, 0, 30)
- aimButton.Position = UDim2.new(0.5, -90, 0, 10)
- aimButton.Parent = gui
- -- Create a TextButton for the "Bringer" button
- local bringerButton = Instance.new("TextButton")
- bringerButton.Text = "Bringer Off"
- bringerButton.Size = UDim2.new(0, 100, 0, 30)
- bringerButton.Position = UDim2.new(0.5, 30, 0, 10) -- Adjust position as needed
- bringerButton.Parent = gui
- -- Variable to keep track of whether aiming is active
- local aimingActive = false
- -- Variable to keep track of whether the bringer is active
- local bringerActive = false
- -- Function to make the camera look at the nearest player's head from the opposite team
- local function aimAtNearestOpponent()
- local player = game.Players.LocalPlayer
- local character = player.Character
- if character then
- local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
- if humanoidRootPart then
- local nearestPlayer = nil
- local shortestDistance = math.huge
- for _, otherPlayer in ipairs(game.Players:GetPlayers()) do
- if otherPlayer.Team ~= player.Team then -- Only consider players from the opposite team
- local otherCharacter = otherPlayer.Character
- if otherCharacter then
- local otherHead = otherCharacter:FindFirstChild("Head")
- if otherHead then
- -- Check if the player is visible to the user
- local ray = Ray.new(humanoidRootPart.Position, (otherHead.Position - humanoidRootPart.Position).Unit * 1000)
- local part, position = game.Workspace:FindPartOnRay(ray, player.Character, false, true)
- if part and part:IsDescendantOf(otherCharacter) then
- local distance = (humanoidRootPart.Position - otherHead.Position).Magnitude
- if distance < shortestDistance then
- nearestPlayer = otherPlayer
- shortestDistance = distance
- end
- end
- end
- end
- end
- end
- if nearestPlayer then
- local nearestCharacter = nearestPlayer.Character
- if nearestCharacter then
- local nearestHead = nearestCharacter:FindFirstChild("Head")
- if nearestHead then
- game.Workspace.CurrentCamera.CFrame = CFrame.new(game.Workspace.CurrentCamera.CFrame.Position, nearestHead.Position)
- end
- end
- end
- end
- end
- end
- -- Function to toggle aiming on/off when the button is clicked
- local function toggleAim()
- aimingActive = not aimingActive
- if aimingActive then
- aimButton.Text = "Stop Aim"
- -- Start aiming
- while aimingActive do
- aimAtNearestOpponent()
- wait()
- end
- else
- aimButton.Text = "Aim"
- -- Stop aiming
- end
- end
- -- Function to toggle aiming on/off when 'x' key is pressed
- local function toggleAimWithKey()
- toggleAim() -- Toggle aiming when 'x' key is pressed
- end
- -- Connect the 'x' key press event to the toggleAimWithKey function
- game:GetService("UserInputService").InputBegan:Connect(function(input)
- if input.KeyCode == Enum.KeyCode.X then
- toggleAimWithKey()
- end
- end)
- -- Function to toggle the bringer on/off when the button is clicked
- local function toggleBringer()
- bringerActive = not bringerActive
- if bringerActive then
- bringerButton.Text = "Bringer On"
- -- Start bringing user to the nearest player
- while bringerActive do
- local player = game.Players.LocalPlayer
- local character = player.Character
- if character then
- local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
- if humanoidRootPart then
- local nearestPlayer = nil
- local shortestDistance = math.huge
- for _, otherPlayer in ipairs(game.Players:GetPlayers()) do
- if otherPlayer.Team ~= player.Team then -- Only consider players from the opposite team
- local otherCharacter = otherPlayer.Character
- if otherCharacter then
- local otherHead = otherCharacter:FindFirstChild("Head")
- if otherHead then
- local distance = (humanoidRootPart.Position - otherHead.Position).Magnitude
- if distance < shortestDistance then
- nearestPlayer = otherPlayer
- shortestDistance = distance
- end
- end
- end
- end
- end
- if nearestPlayer then
- local nearestCharacter = nearestPlayer.Character
- if nearestCharacter then
- local nearestHead = nearestCharacter:FindFirstChild("Head")
- if nearestHead then
- humanoidRootPart.CFrame = CFrame.new(nearestHead.Position)
- end
- end
- end
- end
- end
- wait()
- end
- else
- bringerButton.Text = "Bringer Off"
- -- Stop bringing user to nearest player
- end
- end
- -- Connect button click events to their respective functions
- aimButton.MouseButton1Click:Connect(toggleAim)
- bringerButton.MouseButton1Click:Connect(toggleBringer)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement