--why is this not a library funciton?!

function randUniform(a, b)
	return a + math.random() * (b - a)
end

function randVector(a, b)
	return Vector3.new(randUniform(a.x, b.x), randUniform(a.y, b.y), randUniform(a.z, b.z))
end


TriggerEffect.Event:Connect(function()
	local liveBlox = CollectionService:GetTagged("blox")
	script.Parent.PointLight:SetAttribute("SpawnTime", workspace.DistributedGameTime)
	verticalBeamPS:SetAttribute("SpawnTime", workspace.DistributedGameTime)
	plasmaBeamA:SetAttribute("SpawnTime", workspace.DistributedGameTime)
	plasmaBeamB:SetAttribute("SpawnTime", workspace.DistributedGameTime)

	dustParticles:Emit(15)
	flashPS:Emit(1)
	shockwave:Emit(1)
	verticalBeamPS:Emit(8)
	verticalBeamPS.Enabled = true

	bloxParticles:Emit(100)

	plasmaBeamA.Enabled = true
	plasmaBeamB.Enabled = true

	if #liveBlox < maxBlox then
		for i = -1, 1, 1 do
			for j = -1, 1, 1 do
				for k = -1, 1, 1 do
					local bloxInstance = blox:Clone()
					bloxInstance.Transparency = 0
					bloxInstance.Parent = workspace

					bloxInstance.Position = bloxSpawnLoc.Position + Vector3.new(i * (blox.Size.x + spacing), j * (blox.Size.y + spacing), k * (blox.Size.z + spacing))

					bloxInstance.Anchored = false
					bloxInstance:ApplyImpulse(randVector(Vector3.new(-hSpeed, 0, -hSpeed), Vector3.new(hSpeed, vSpeed, hSpeed)))
					bloxInstance:ApplyAngularImpulse(randVector(Vector3.new(-0.0005, -0.0005, -0.0005), Vector3.new(0.0005, 0.0005, 0.0005)))

					bloxInstance:SetAttribute("ID", math.random())
					bloxInstance:SetAttribute("SpawnTime", workspace.DistributedGameTime)
					bloxInstance:SetAttribute("Lifetime", randUniform(2.0, 3.0))


					CollectionService:AddTag(bloxInstance, "blox")
				end
			end
		end
	end
end)
