----------------------------------------------------------------------
--------------------[ SHOCKWAVE HANDLING ]----------------------------
----------------------------------------------------------------------


local createShockwave = script:WaitForChild("createShockwave")
createShockwave.OnServerEvent:connect(function(_, Center, Radius, gunIgnore, S)
	local Shockwave = Instance.new("Part")
	Shockwave.BrickColor = S.shockwaveSettings.Color
	Shockwave.Material = Enum.Material.SmoothPlastic
	Shockwave.Name = "Shockwave"
	Shockwave.Anchored = true
	Shockwave.CanCollide = false
	Shockwave.FormFactor = Enum.FormFactor.Symmetric
	Shockwave.Size = V3(1, 1, 1)
	Shockwave.BottomSurface = Enum.SurfaceType.Smooth
	Shockwave.TopSurface = Enum.SurfaceType.Smooth
	local Mesh = Instance.new("SpecialMesh")
	Mesh.MeshType = Enum.MeshType.Sphere
	Mesh.Scale = V3()
	Mesh.Parent = Shockwave
	Shockwave.Parent = gunIgnore
	Shockwave.CFrame = CF(Center)
	spawn(function()
		local t0 = tick()
		while true do
			local Alpha = math.min((tick() - t0) / S.shockwaveSettings.Duration, 1)
			local Scale = 2 * Radius * Alpha
			Mesh.Scale = V3(Scale, Scale, Scale)
			Shockwave.Transparency = Alpha
			if Alpha == 1 then break end
			wait()
		end
		Shockwave:Destroy()
	end)
end)
