--BROUGHT TO YOU BY RobloxScripter.com!--
local Rem = game:GetService("ReplicatedStorage"):WaitForChild("ChestSmashing"):WaitForChild("attack")
local Chest = game:GetService("Workspace").Chests
local Player = game:GetService("Players").LocalPlayer
local function GetClosestPart()
local Closest, Distance = nil, math.huge
local Character = Player.Character or Player.CharacterAdded:Wait()
for i, v in next, Chest:GetDescendants() do
if v.Name == "Main" and v:IsA("BasePart") then
local LocalDistance = (Character:GetPivot().Position - v.Position).Magnitude
if LocalDistance < Distance then
Closest = v
Distance = LocalDistance
end
end
end
return Closest
end
while task.wait(2) do
local Closest = GetClosestPart()
local Character = Player.Character or Player.CharacterAdded:Wait()
if (Closest and Character) then
Character:PivotTo(Closest.CFrame)
Rem:FireServer(Closest.Parent:FindFirstChild("NumberOfHitbox", true).Value, Closest.Parent, "Start")
end
end