Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Create the GUI
- local Players = game:GetService("Players")
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local gui = Instance.new("ScreenGui")
- gui.Parent = Players.LocalPlayer:WaitForChild("PlayerGui")
- gui.DisplayOrder = 10
- local frame = Instance.new("Frame")
- frame.Size = UDim2.new(0, 200, 0, 150)
- frame.Position = UDim2.new(0, 30, 0.5, -75)
- frame.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
- frame.BorderSizePixel = 2
- frame.Parent = gui
- local targetLabel = Instance.new("TextLabel")
- targetLabel.Size = UDim2.new(1, 0, 0, 30)
- targetLabel.Position = UDim2.new(0, 0, 0, 0)
- targetLabel.Text = "Target: None"
- targetLabel.BackgroundColor3 = Color3.fromRGB(200, 200, 200)
- targetLabel.Parent = frame
- local startButton = Instance.new("TextButton")
- startButton.Size = UDim2.new(0, 80, 0, 30)
- startButton.Position = UDim2.new(0.1, 0, 0.3, 0)
- startButton.Text = "Start Hitting"
- startButton.Parent = frame
- local stopButton = Instance.new("TextButton")
- stopButton.Size = UDim2.new(0, 80, 0, 30)
- stopButton.Position = UDim2.new(0.1, 0, 0.6, 0)
- stopButton.Text = "Stop Hitting"
- stopButton.Parent = frame
- local scriptRunning = false
- local currentTarget = nil
- local player = Players.LocalPlayer
- local function firePunchEvent(targetName)
- local args = {
- [1] = 4,
- [2] = workspace:WaitForChild("Characters"):WaitForChild(targetName)
- }
- ReplicatedStorage:WaitForChild("MainEvents"):WaitForChild("PUNCHEVENT"):FireServer(unpack(args))
- end
- local function findClosestPlayer()
- local closestPlayer = nil
- local closestDistance = math.huge -- Start with a very high distance
- for _, otherPlayer in pairs(Players:GetPlayers()) do
- if otherPlayer ~= player and otherPlayer.Character and otherPlayer.Character:FindFirstChild("HumanoidRootPart") then
- local distance = (player.Character.HumanoidRootPart.Position - otherPlayer.Character.HumanoidRootPart.Position).magnitude
- if distance < closestDistance then
- closestDistance = distance
- closestPlayer = otherPlayer
- end
- end
- end
- return closestPlayer
- end
- local function updateTarget()
- local closestPlayer = findClosestPlayer()
- if closestPlayer then
- currentTarget = closestPlayer.Name
- targetLabel.Text = "Target: " .. currentTarget
- else
- targetLabel.Text = "Target: None"
- end
- end
- startButton.MouseButton1Click:Connect(function()
- updateTarget() -- Update target when starting
- if currentTarget then
- scriptRunning = true
- while scriptRunning do
- firePunchEvent(currentTarget) -- Fire the punch event for the target
- wait(0.1) -- Adjust wait time as necessary
- end
- end
- end)
- stopButton.MouseButton1Click:Connect(function()
- scriptRunning = false
- end)
- -- Optionally, you can call updateTarget at any time to refresh the target
- Players.LocalPlayer:GetMouse().Button1Down:Connect(function()
- updateTarget() -- Update target when clicked
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement