FastCast/ActiveCast spamming me a warning about a single ray segment

  1. What do you want to achieve? Keep it simple and clear!
    I want to make a simple stun gun system from skibidi toilet series (for a game im working for) that stuns the enemies using FastCast and making it shoot multiple enemies

  2. What is the issue? Include screenshots / videos if possible!
    So when I shoot my projectile with ActiveCast/FastCast, it starts spamming me a warning like this:


    but the projectile fully works, my friend says that if I get this, that means something is wrong with my code. What could it be? I tried everything!

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve tried lookin up on devforum, using ChatGPT and everything but no good fixes found

Here is my code:

local module = {}
module.__index = module

local Casters = require(script.PlayerCasters)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UtilityModules = ReplicatedStorage:WaitForChild("Packages")

local Signal = require(UtilityModules.Signal)
local Trove = require(UtilityModules.Trove)
local FastCast = require(UtilityModules.FastCast)

FastCast.VisualizeCasts = true

type SettingsData = {
	Character: Model,
	ProjectileModel: BasePart,

	Origin: Vector3,
	Offset: CFrame,
	Direction: Vector3,
	Distance: number,
	Velocity: number?,
	MaxHits: number?,

	Params: RaycastParams,
	Callback: any?,
}

local function SetupCaster(characterName)
	local caster = FastCast.new()

	caster.RayPierced:Connect(function(cast, result, velocity)
		local data = cast.UserData
		if data and data.RegisterHit then
			data.RegisterHit(cast, result, velocity, data.Bullet)
		end
	end)

	caster.LengthChanged:Connect(function(cast, segmentOrigin, segmentDirection, length, _, bullet)
		local data = cast.UserData
		if not bullet or not data then return end

		local bulletLength = bullet.Size.Z / 2
		local cf = CFrame.lookAt(segmentOrigin, segmentOrigin + segmentDirection)
		bullet.CFrame = cf * CFrame.new(0, 0, -(length - bulletLength)) * (data.Offset or CFrame.identity)
	end)

	return caster
end

function module.new(Settings: SettingsData)
	local self = setmetatable({}, module)
	self.HitSignal = Signal.new()

	local character = Settings.Character
	local characterName = character.Name

	local caster = Casters[characterName]
	if not caster then
		caster = SetupCaster(characterName)
		Casters[characterName] = caster
	end

	local trove = Trove.new()
	local behavior = FastCast.newBehavior()

	local bullet = Settings.ProjectileModel:Clone()
	bullet:SetAttribute("MaxHits", Settings.MaxHits or 1)
	bullet:SetAttribute("Hits", 0)
	bullet.Parent = workspace.Effects

	behavior.RaycastParams = Settings.Params
	behavior.MaxDistance = Settings.Distance or 300
	behavior.CosmeticBulletTemplate = bullet
	behavior.CosmeticBulletContainer = workspace.Effects

	local hitNPCs = {}

	local function RegisterHit(Cast, Result, Velocity, Bullet)
		local npc = Result.Instance:FindFirstAncestorOfClass("Model")
		if npc and npc:FindFirstChild("Humanoid") and not hitNPCs[npc] then
			hitNPCs[npc] = true

			local hits = bullet:GetAttribute("Hits") or 0
			hits += 1
			bullet:SetAttribute("Hits", hits)

			self.HitSignal:Fire(Cast, Result, Velocity, bullet)

			if hits >= (bullet:GetAttribute("MaxHits") or 1) then
				Cast:Terminate()
				print("terminate a")
			end
		end
	end

	local piercedModels = {}

	behavior.CanPierceFunction = function(cast, result, velocity)
		local model = result.Instance:FindFirstAncestorOfClass("Model")
		if (model and model:FindFirstChild("Humanoid")) or result.Instance.Transparency > 0.4 then
			if piercedModels[model] then return false end
			table.insert(piercedModels, model)
			return true
		else
			return false
		end
	end

	local cast = caster:Fire(Settings.Origin, Settings.Direction, Settings.Velocity or 1, behavior)
	cast.UserData = {
		RegisterHit = RegisterHit,
		Bullet = bullet,
		Offset = Settings.Offset,
	}

	trove:Add(function()
		if bullet then bullet:Destroy() end
	end)

	trove:Add(function()
		cast:Terminate()
	end)

	return self
end

return module

I would appreciate a lot any kind or type of help, thank you very much!