Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- LocalScript inside StarterPlayer -> StarterPlayerScripts
- local player = game.Players.LocalPlayer
- local character = player.Character or player.CharacterAdded:Wait()
- local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
- local ball = workspace:WaitForChild("Ball") -- Assuming the ball is named "Ball" in the workspace
- local maxDistance = 10 -- Maximum distance for auto-press to trigger
- local uis = game:GetService("UserInputService")
- local rs = game:GetService("RunService")
- -- Function to simulate key press (F key)
- local function simulateKeyPress()
- -- Create a new input object simulating an F key press
- local inputObject = Instance.new("InputObject")
- inputObject.UserInputType = Enum.UserInputType.Keyboard
- inputObject.KeyCode = Enum.KeyCode.F
- -- Fire the input began event (key down)
- uis.InputBegan:Fire(inputObject, false)
- end
- -- Continuous check every frame
- rs.RenderStepped:Connect(function()
- -- Calculate the distance between the player and the ball
- local distance = (humanoidRootPart.Position - ball.Position).Magnitude
- -- Check if the ball is within the range
- if distance <= maxDistance then
- simulateKeyPress() -- Simulate the F key press
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment