local Players = game:GetService("Players") local LocalPlayer = Players.LocalPlayer local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait() local UserInputService = game:GetService("UserInputService") local RunService = game:GetService("RunService") local ReplicatedStorage = game:GetService("ReplicatedStorage") local Toggle = false local function GetPart(Model) if Model and Model.ClassName == "Model" then if Model.PrimaryPart then return Model.PrimaryPart elseif Model:FindFirstChild("Totem") then return Model:FindFirstChild("Totem") elseif Model:FindFirstChildWhichIsA("Part") then return Model:FindFirstChildWhichIsA("Part") elseif Model:FindFirstChildWhichIsA("BasePart") then return Model:FindFirstChildWhichIsA("BasePart") end end return nil end UserInputService.InputBegan:Connect(function(Input, GameProcessed) if GameProcessed then return end if Input.KeyCode == Enum.KeyCode.R then Toggle = not Toggle end end) RunService.RenderStepped:Connect(function() Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait() if Toggle and Character and Character:FindFirstChild("HumanoidRootPart") then local Closest local ClosestDistance = 12.5 for _,v in workspace:GetChildren() do local Part = GetPart(v) if Part and Character and v ~= Character and (Character.HumanoidRootPart.Position - Part.Position).Magnitude < ClosestDistance and v:FindFirstChild("Health") then Closest = Part ClosestDistance = (Character.HumanoidRootPart.Position - Part.Position).Magnitude end end for _,v in workspace.Critters:GetChildren() do local Part = GetPart(v) if Part and Character and (Character.HumanoidRootPart.Position - Part.Position).Magnitude < ClosestDistance and v:FindFirstChild("Health") then Closest = Part ClosestDistance = (Character.HumanoidRootPart.Position - Part.Position).Magnitude end end if Closest then ReplicatedStorage.Events.SwingTool:FireServer(os.clock(),{Closest}) end end end)