local function l(l)local b=Instance.new("\080\097\114\116\105\099\108\101\069\109\105\116\116\101\114")b.Name="\080\097\114\116\105\099\108\101\115"b.Parent=l b.Texture="\114\098\120\097\115\115\101\116\105\100\058\047\047\051\049\050\055\050\055\057\054\056\052"b.Size=NumberSequence.new(.75)b.Acceleration=Vector3.new(0,-15,0)b.Lifetime=NumberRange.new(.5,1.5)b.Speed=NumberRange.new(15)b.SpreadAngle=Vector2.new(30,30)b.Rate=20 local A=coroutine.create(function()wait(.75)b.Enabled=false DebrisService:AddItem(b,.75)end)coroutine.resume(A)return b end local function b()local l=mapManager.getMap()if not l then return false end local b=l:FindFirstChild("\072\105\103\104\080\111\105\110\116\115")local A=l:FindFirstChild("\077\101\100\105\117\109\080\111\105\110\116\115")local L=l:FindFirstChild("\076\111\119\080\111\105\110\116\115")return{b,A,L}end local function A(l)local A=l.Character:FindFirstChild("\072\117\109\097\110\111\105\100\082\111\111\116\080\097\114\116")if not A then return end local L=A.Position+PUNCH_HEIGHT_OFFSET local K=A.CFrame.lookVector local a=Ray.new(L,K*PUNCH_RANGE)local Z=b()if not Z then return end local M,R=workspace:FindPartOnRayWithWhitelist(a,Z,true)return M end local function L(b,A)local L=getModel(b)if L and isModelDestroyed(b,destroyedModels)then return end local K=getTopAncestor(b)local a=K.Parent.Name DebrisService:AddItem(K,.01)table.insert(destroyedModels,K)if K:IsA("\077\111\100\101\108")then breakModel(K)else K.CanCollide=false end createSmoke(K)local Z=createDebris(K)l(Z)leaderboardManager:incrementStat(A,"\080\111\105\110\116\115",gameSettings.pointValues[a])end

local function createParticles(parentPart)
	local particles = Instance.new("ParticleEmitter")
	particles.Name = "Particles"
	particles.Parent = parentPart
	particles.Texture = "rbxassetid://3127279684" -- Points icon
	particles.Size = NumberSequence.new(.75)
	particles.Acceleration = Vector3.new(0, -15, 0)
	particles.Lifetime = NumberRange.new(0.5, 1.5)
	particles.Speed = NumberRange.new(15)
	particles.SpreadAngle = Vector2.new(30, 30)
	particles.Rate = 20
	
	local particleThread = coroutine.create(function()
		wait(0.75)
		particles.Enabled = false
		DebrisService:AddItem(particles, 0.75)
	end)
	coroutine.resume(particleThread)
	
	return particles
end

local function getHittableWhitelist()
	local map = mapManager.getMap()
	if not map then 
		return false
	end
	
	local highPoints = map:FindFirstChild("HighPoints")
	local mediumPoints = map:FindFirstChild("MediumPoints")
	local lowPoints = map:FindFirstChild("LowPoints")
	
	return {highPoints, mediumPoints, lowPoints}
end

local function getHit(player)
	-- Destroy parts touching the player's right hand if they are in the map and not a prop (and award points)
	local humanoidRootPart = player.Character:FindFirstChild("HumanoidRootPart")
	if not humanoidRootPart then return end
	
	local origin = humanoidRootPart.Position + PUNCH_HEIGHT_OFFSET -- Lower the origin
	local aimDirection = humanoidRootPart.CFrame.lookVector
	
	-- create a ray aiming the same way as player
	local ray = Ray.new(origin, aimDirection * PUNCH_RANGE)

	-- Create a whitelist for the map folders
	local hittableWhitelist = getHittableWhitelist()
	if not hittableWhitelist then return end
	
	-- raycast		
	local hit, position = workspace:FindPartOnRayWithWhitelist(ray, hittableWhitelist, true)
	
	return hit
end

local function handleHit(hit, player)
	local model = getModel(hit)
	if model and isModelDestroyed(hit, destroyedModels) then
		return
	end
		
	-- Get topmost ancestor (for cases where touched part is part of a model)
	local topAncestor = getTopAncestor(hit)

	-- Points type matching name of ancestor folder
	local pointsType = topAncestor.Parent.Name
	
	-- Add member to debris
	DebrisService:AddItem(topAncestor, 0.01)
			
	-- Add model to destroy model table to track before Debris does garbage
	-- collection and removes it
	table.insert(destroyedModels, topAncestor)
			
	-- Make part/model non-collidable
	if topAncestor:IsA("Model") then
		breakModel(topAncestor)
	else
		topAncestor.CanCollide = false
	end
	
	createSmoke(topAncestor)
	local debris = createDebris(topAncestor)
	createParticles(debris)

	-- Award points
	leaderboardManager:incrementStat(player, "Points", gameSettings.pointValues[pointsType])
end
