local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character
local Root = Character:FindFirstChild("HumanoidRootPart")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ENABLED = true
local function getNearbyPlayers()
local nearby = {}
for _, player in ipairs(Players:GetPlayers()) do
if player ~= LocalPlayer and player.Character then
local proot = player.Character:FindFirstChild("HumanoidRootPart")
if proot then
local distance = (Root.Position - proot.Position).Magnitude
if distance <= 20 then
table.insert(nearby, player)
end
end
end
end
return nearby
end
game:GetService("UserInputService").InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end
if input.KeyCode == Enum.KeyCode.K then
ENABLED = not ENABLED
end
end)
game:GetService("RunService").Heartbeat:Connect(function()
if ENABLED then
local nearbyPlayers = getNearbyPlayers()
for _, player in ipairs(nearbyPlayers) do
local targetChar = player.Character
if targetChar then
local humanoid = targetChar:FindFirstChild("Humanoid")
if humanoid then
local args = {
humanoid,
"Punch",
false
}
ReplicatedStorage:FindFirstChild("Remote").Events.CombatUsed:FireServer(unpack(args))
end
end
end
end
end)