-- Luke



local button = script.Parent
local players = game:GetService('Players')

local DEBOUNCE_TIME = 5
local debounce = false


button.Touched:connect(function(hit)
	if hit and hit.Parent then
		local humanoid = hit.Parent:FindFirstChild('Humanoid')
		local hrp = hit.Parent:FindFirstChild('HumanoidRootPart')
		if hrp and humanoid and humanoid.Health > 0 then
			local player = players:GetPlayerFromCharacter(hit.Parent)
			if not debounce then
				debounce = true
				
				local nearestAccessory = nil
				local nearestDistance = nil
				for _,accessory in pairs(workspace:GetChildren()) do
					if accessory:IsA('Accessory') then
						local handle = accessory:FindFirstChild('Handle')
						if handle then
							local distance = (handle.Position-button.Position).magnitude
							if not nearestDistance or distance < nearestDistance then
								nearestDistance = distance
								nearestAccessory = accessory
							end
						end
					end
				end
				if nearestAccessory then
					local accessory = nearestAccessory:clone()
					accessory.Parent = hit.Parent
				end

				wait(DEBOUNCE_TIME)
				debounce = false
			end
		end
	end
end)




