Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ================================================================= --
- -- SERVICES --
- -- ================================================================= --
- local Players = game:GetService("Players")
- local RunService = game:GetService("RunService")
- local VirtualInputManager = game:GetService("VirtualInputManager")
- local Workspace = game:GetService("Workspace")
- local UserInputService = game:GetService("UserInputService")
- -- ================================================================= --
- -- PLAYER VARIABLES --
- -- ================================================================= --
- local player = Players.LocalPlayer
- local character = player.Character or player.CharacterAdded:Wait()
- local hrp = character:WaitForChild("HumanoidRootPart")
- local ballsFolder = Workspace:WaitForChild("Balls")
- -- ================================================================= --
- -- RADIUS CONFIGURATION --
- -- ================================================================= --
- local baseHitRadius = 35 -- The default radius when auto radius is off
- local maxRadius = 100 -- The maximum radius when auto radius is on
- local smoothingSpeed = 8 -- Higher value means the radius changes faster
- local speedMultiplier = 1.5 -- Adjust this value to change how much speed affects the radius
- -- ================================================================= --
- -- SPHERE VISUALS --
- -- ================================================================= --
- local sphereTransparency = 0.8
- local sphereColor = Color3.fromRGB(255, 0, 0)
- local sphere = Instance.new("Part")
- sphere.Shape = Enum.PartType.Ball
- sphere.Anchored = true
- sphere.CanCollide = false
- sphere.CanTouch = false
- sphere.CanQuery = false
- sphere.Massless = true
- sphere.Material = Enum.Material.Neon
- sphere.Color = sphereColor
- sphere.Transparency = sphereTransparency
- sphere.Size = Vector3.new(baseHitRadius * 2, baseHitRadius * 2, baseHitRadius * 2)
- sphere.Parent = Workspace
- -- ================================================================= --
- -- STATE VARIABLES --
- -- ================================================================= --
- local debounce = false
- local autoRadiusEnabled = false
- local currentRadius = baseHitRadius
- -- ================================================================= --
- -- HELPER FUNCTIONS --
- -- ================================================================= --
- --- @dev Simulates a key press for the 'F' key.
- local function pressF()
- if debounce then return end
- debounce = true
- VirtualInputManager:SendKeyEvent(true, Enum.KeyCode.F, false, game)
- task.wait(0.03)
- VirtualInputManager:SendKeyEvent(false, Enum.KeyCode.F, false, game)
- task.wait(0.15)
- debounce = false
- end
- --- @dev Checks if the player's character has a 'Highlight' instance.
- --- @return boolean True if highlighted, false otherwise.
- local function isHighlighted()
- if character then
- for _, child in ipairs(character:GetChildren()) do
- if child:IsA("Highlight") then
- return true
- end
- end
- end
- return false
- end
- -- ================================================================= --
- -- EVENT LISTENERS --
- -- ================================================================= --
- -- Handle character respawns to ensure the script has the correct references.
- player.CharacterAdded:Connect(function(char)
- character = char
- hrp = character:WaitForChild("HumanoidRootPart")
- end)
- -- Main game loop that runs every frame.
- RunService.RenderStepped:Connect(function(dt)
- if not (hrp and hrp.Parent) then return end
- local closestBall = nil
- local closestDist = math.huge
- -- Find the closest ball in the 'Balls' folder.
- for _, ball in pairs(ballsFolder:GetChildren()) do
- if ball:IsA("BasePart") then
- local dist = (ball.Position - hrp.Position).Magnitude
- if dist < closestDist then
- closestDist = dist
- closestBall = ball
- end
- end
- end
- -- If no balls are found, hide the sphere and exit.
- if not closestBall then
- sphere.CFrame = hrp.CFrame + Vector3.new(0, -1000, 0) -- hide sphere
- return
- end
- -- Calculate the target radius based on whether auto radius is enabled and the ball's speed.
- local targetRadius = baseHitRadius
- if autoRadiusEnabled then
- local ballSpeed = closestBall.Velocity.Magnitude
- -- The radius is proportional to the ball's speed, clamped between the base and max values.
- -- 'speedMultiplier' can be adjusted to make the radius change more or less aggressively.
- targetRadius = math.clamp(ballSpeed * speedMultiplier, baseHitRadius, maxRadius)
- end
- -- Smoothly change the current radius towards the target radius.
- currentRadius = currentRadius + (targetRadius - currentRadius) * math.clamp(dt * smoothingSpeed, 0, 1)
- -- Update the sphere's size and position to match the closest ball.
- sphere.Size = Vector3.new(currentRadius * 2, currentRadius * 2, currentRadius * 2)
- sphere.CFrame = closestBall.CFrame
- -- Check if conditions are met to press 'F'.
- if isHighlighted() and closestDist <= currentRadius then
- pressF()
- end
- end)
- -- Toggle the auto radius feature with the 'R' key.
- UserInputService.InputBegan:Connect(function(input)
- if input.KeyCode == Enum.KeyCode.R then
- autoRadiusEnabled = not autoRadiusEnabled
- print("Auto Radius Enabled:", autoRadiusEnabled)
- -- Reset the radius immediately when toggled off for a cleaner feel
- if not autoRadiusEnabled then
- currentRadius = baseHitRadius
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment