Turbofusion gun kit broke today?

yo, so basically i added turbofusion guns to my game, and it worked fine for a couple of days until today, the script appears to have broke in some way, i know this isn’t my fault because i have never even touched the lines of code that are returning the errors
but it’s “Unable to cast Value to Object”
the problematic lines are said to be 743, 983 and 1319
it was in a few lines with “AdvRaycast” and stuff like that
this isn’t my code, but i’ll send it and hopefully the problem would be fixed? because this literally breaks my game and causes a ton of lag, here are codes that are parents of the lines:

function AdvRayCast(Origin, Direction, Dist, CustomIgnore, Ignore)
	local NewIgnore = (CustomIgnore and CustomIgnore or Ignore)
	local NewRay = Ray.new(Origin, Direction * (Dist > 999 and 999 or Dist))
	local HitObj, HitPos = game.Workspace:FindPartOnRayWithIgnoreList(NewRay, NewIgnore)
	local LastPos = HitPos
	local FinalHitObj, FinalHitPos = nil, nil
	local RepTimes = math.floor(Dist / 999)
	if (not HitObj) and (Dist > 999) then
		for i = 0, RepTimes do
			local NewDist = (i == RepTimes and  (Dist - (LastPos - Origin).magnitude) or 999)
			local Ray2 = Ray.new(LastPos, Direction * NewDist)
			local HitObj2, HitPos2 = game.Workspace:FindPartOnRayWithIgnoreList(Ray2, NewIgnore)
			if i ~= RepTimes then
				if HitObj2 then
					FinalHitObj, FinalHitPos = HitObj2, HitPos2
					break
				end
			elseif i == RepTimes then
				FinalHitObj, FinalHitPos = HitObj2, HitPos2
			end
			LastPos = HitPos2
		end
		return FinalHitObj, FinalHitPos
	elseif HitObj or (Dist <= 999) then
		return HitObj, HitPos
	end
end
function PenetrateWall(HitPos, Direction, HitHumanoid, OriginPos, Bullet, Player)
	local Ignore = {
		(game.Players:GetPlayerFromCharacter(Gun.Parent) and game.Players:GetPlayerFromCharacter(Gun.Parent).Character or nil);
		Ignore_Folder;
		Gun_Ignore ;--Ignore_Model;
	}
	
	local HitDist = (HitPos - OriginPos).magnitude
	local Thickness, Wall, WallHitPos, WallNorm = 0, nil, nil, nil
	for i = 0.1, S.Penetration, 0.1 do
		local WallRay = Ray.new(HitPos + (Direction * i), -Direction)
		local TempWall, TempWallHitPos, TempWallNorm = game.Workspace:FindPartOnRayWithIgnoreList(WallRay, Ignore)
		if TempWall then
			Thickness = i
			Wall, WallHitPos, WallNorm = TempWall, TempWallHitPos, TempWallNorm
			break
		end
	end
	if Wall then
		CreateBulletHole(WallHitPos, Wall, WallNorm)
		if S.InstantHit then
			local HitObj2, HitPos2, HitNorm2 = nil, nil, nil
			if HitHumanoid then
				HitObj2, HitPos2, HitNorm2 = AdvRayCast(WallHitPos, Direction, S.BulletRange - HitDist, {HitHumanoid.Parent,unpack(Ignore), Ignore})
			else
				HitObj2, HitPos2, HitNorm2 = AdvRayCast(WallHitPos, Direction, S.BulletRange - HitDist, nil, Ignore)
			end
			Damage(HitObj2, HitPos2, HitNorm2, Player)
			return HitPos2
		else
			local LastPos = WallHitPos
			local TotalDistTraveled = 0
			QuickSpawn(function()
				while true do
					local Delta = 1/60
					
					if TotalDistTraveled >= S.BulletRange - HitDist then
						Bullet:Destroy()
						break
					end

					Bullet.Position = Bullet.Position + Bullet.Velocity * Delta
					Bullet.Velocity = Bullet.Velocity - VEC3(0, S.BulletDropPerSecond, 0) * Delta

					local DistTraveled = (Bullet.Position - LastPos).magnitude
					local NewDirection = (Bullet.Position - LastPos).unit
					local TempHitObj, TempHitPos, TempHitNorm = nil, nil, nil
					if HitHumanoid then
						TempHitObj, TempHitPos, TempHitNorm = AdvRayCast(LastPos, NewDirection, DistTraveled, {HitHumanoid.Parent,unpack(Ignore)}, Ignore)
					else
						TempHitObj, TempHitPos, TempHitNorm = AdvRayCast(LastPos, NewDirection, DistTraveled, nil, Ignore)
					end
					if TempHitObj then
						Damage(TempHitObj, TempHitPos, TempHitNorm, Player)
						Bullet:Destroy()
						return TempHitPos
					else
						LastPos = Bullet.Position
						TotalDistTraveled = TotalDistTraveled + DistTraveled
					end
					
					Stepped:Wait()
				end
			end)
		end
	else
		if Bullet then Bullet:Destroy() end
		return HitPos
	end
end
script.FireProjectile.OnServerEvent:Connect(function(_, Player, OriginCF, OriginPos, Aimed, CurrentSpread)
	if Gun.Ammo.Value <= 0 then return end
	Gun.Ammo.Value -= 1

	local Ignore = {
		Player.Character,
		Gun_Ignore,
		Ignore_Folder
	}

	for _ = 1, (S.GunType.Shot and S.ShotAmount or 1) do
		local BSpread = CFANG(
			RAD(RAND(-CurrentSpread, CurrentSpread) / 20),
			RAD(RAND(-CurrentSpread, CurrentSpread) / 20),
			RAD(RAND(-CurrentSpread, CurrentSpread) / 20)
		)
		local Direction = (CF(OriginCF.p, OriginCF.p + OriginCF.lookVector) * BSpread).lookVector

		if S.InstantHit then
			local HitObj, HitPos, HitNorm = AdvRayCast(Main.CFrame.p, Direction, S.BulletRange, nil, Ignore)
			local HitHumanoid = nil
			if HitObj then
				if S.GunType.Explosive then
					if S.ExplosionSound ~= "" then
						local SoundPart = Instance.new("Part")
						SoundPart.Transparency = 1
						SoundPart.Anchored = true
						SoundPart.CanCollide = false
						SoundPart.CFrame = CFrame.new(HitPos)
						SoundPart.Parent = game.Workspace

						local Sound = Instance.new("Sound")
						Sound.Pitch = S.ExplosionSoundPitch
						Sound.SoundId = S.ExplosionSound
						Sound.Volume = S.ExplosionSoundVolume
						Sound.Parent = SoundPart
						Sound:Play()

						delay(1 / 20, function()
							SoundPart:Destroy()
						end)
					end
					CreateBulletHole(HitPos, HitObj, HitNorm)
					--Gun.Server_Main.BulletHole:FireServer(HitPos, HitObj)
					CreateShockwave(HitPos, S.ExplosionRadius)
					local E = Instance.new("Explosion")
					E.BlastPressure = S.ExplosionPressure
					E.BlastRadius = S.ExplosionRadius
					E.DestroyJointRadiusPercent = (S.RangeBasedDamage and 0 or 1)
					E.ExplosionType = S.ExplosionType
					E.Position = HitPos
					E.Hit:connect(function(HObj, HDist)
						if HObj.Name == "Torso" and (not HObj:IsDescendantOf(Player.Character)) then
							if S.RangeBasedDamage then
								local Dir = (HObj.Position - HitPos).unit
								local H, P = AdvRayCast(HitPos - Dir, Dir, 999, nil, Ignore)
								local RayHitHuman = H:IsDescendantOf(HObj.Parent)
								if (S.RayCastExplosions and RayHitHuman) or (not S.RayCastExplosions) then
									local HitHumanoid = FindFirstClass(HObj.Parent, "Humanoid")
									if HitHumanoid and HitHumanoid.Health > 0 and IsEnemy(HitHumanoid) then
										local DistFactor = HDist / S.ExplosionRadius
										local DistInvert = math.max(1 - DistFactor,0)
										local NewDamage = DistInvert * S.Damage

										local CreatorTag = Instance.new("ObjectValue")
										CreatorTag.Value = Player
										CreatorTag.Name = "creator"
										CreatorTag.Parent = HitHumanoid
										HitHumanoid:TakeDamage(NewDamage)
										--Gun.Server_Main.Damage:FireServer(HitHumanoid, NewDamage, Player)
										--MarkHit()
										script.MarkHit:FireClient(Player)
									end
								end
							else
								local HitHumanoid = FindFirstClass(HObj.Parent, "Humanoid")
								if HitHumanoid and HitHumanoid.Health > 0 and IsEnemy(HitHumanoid) then
									--MarkHit()
									script.MarkHit:FireClient(Player)
								end
							end
						end
					end)
					E.Parent = game.Workspace
				else
					HitHumanoid = Damage(HitObj, HitPos, HitNorm, Player)
				end
			end
			local FinalHitPos = HitPos
			if S.Penetration > 0 and (not S.GunType.Explosive) then
				FinalHitPos = PenetrateWall(HitPos, Direction, HitHumanoid, OriginPos, nil, Player)
			end
			if S.BulletTrail and S.TrailTransparency ~= 1 then
				local Trail = Instance.new("Part")
				Trail.BrickColor = S.TrailColor
				Trail.Transparency = S.TrailTransparency
				Trail.Anchored = true
				Trail.CanCollide = false
				Trail.Size = VEC3(1, 1, 1)
				local Mesh = Instance.new("BlockMesh")
				Mesh.Offset = VEC3(0, 0, -(FinalHitPos - OriginPos).magnitude / 2)
				Mesh.Scale = VEC3(S.TrailThickness, S.TrailThickness, (FinalHitPos - OriginPos).magnitude)
				Mesh.Parent = Trail
				Trail.Parent = Gun_Ignore
				Trail.CFrame = CF(OriginPos, FinalHitPos)
				QuickSpawn(function()--delay(S.TrailVisibleTime, function()
					wait(S.TrailVisibleTime)
					if S.TrailDisappearTime > 0 then
						local X = 0
						while true do
							if X == 90 then break end
							if (not Selected) then break end
							local NewX = X + (1.5 / S.TrailDisappearTime)
							X = (NewX > 90 and 90 or NewX)
							local Alpha = X / 90
							Trail.Transparency = NumLerp(S.TrailTransparency, 1, Alpha)
							Stepped:Wait()
						end
						Trail:Destroy()
					else
						Trail:Destroy()
					end
				end)
			end
		else
			local Bullet = CreateBullet(Direction)
			local LastPos = Main.CFrame.p
			local TotalDistTraveled = 0
			local HitHumanoid = nil
			QuickSpawn(function()
				while true do
					local Delta = 1/60 --Heartbeat:Wait()
					if TotalDistTraveled >= S.BulletRange then
						Bullet:Destroy()
						break
					end

					Bullet.Position = Bullet.Position + Bullet.Velocity * Delta
					Bullet.Velocity = Bullet.Velocity - VEC3(0, S.BulletDropPerSecond, 0) * Delta

					local DistTraveled = (Bullet.Position - LastPos).magnitude
					local HitObj, HitPos, HitNorm = AdvRayCast(LastPos, (Bullet.Position - LastPos).unit, DistTraveled, Ignore)
					if HitObj then
						if S.GunType.Explosive then
							if S.ExplosionSound ~= "" then
								local Sound = Instance.new("Sound")
								Sound.Pitch = S.ExplosionSoundPitch
								Sound.SoundId = S.ExplosionSound
								Sound.Volume = S.ExplosionSoundVolume
								Sound.Parent = Bullet
								Sound:Play()
							end
							CreateBulletHole(HitPos, HitObj, HitNorm)
							--Gun.Server_Main.BulletHole:FireServer(HitPos, HitObj, HitNorm)
							CreateShockwave(HitPos, S.ExplosionRadius)
							local E = Instance.new("Explosion")
							E.BlastPressure = S.ExplosionPressure
							E.BlastRadius = S.ExplosionRadius
							E.DestroyJointRadiusPercent = (S.RangeBasedDamage and 0 or 1)
							E.ExplosionType = S.ExplosionType
							E.Position = HitPos
							E.Hit:connect(function(HObj, HDist)
								if HObj.Name == "Torso" and (not HObj:IsDescendantOf(Player.Character)) then
									if S.RangeBasedDamage then
										local Dir = (HObj.Position - HitPos).unit
										local H, P = AdvRayCast(HitPos - Dir, Dir, 999, Ignore)
										local RayHitHuman = H:IsDescendantOf(HObj.Parent)
										if (S.RayCastExplosions and RayHitHuman) or (not S.RayCastExplosions) then
											local HitHumanoid = FindFirstClass(HObj.Parent, "Humanoid")
											if HitHumanoid and HitHumanoid.Health > 0 and IsEnemy(HitHumanoid) then
												local DistFactor = HDist / S.ExplosionRadius
												local DistInvert = math.max(1 - DistFactor,0)
												local NewDamage = DistInvert * S.Damage

												local CreatorTag = Instance.new("ObjectValue")
												CreatorTag.Value = Player
												CreatorTag.Name = "creator"
												CreatorTag.Parent = HitHumanoid
												HitHumanoid:TakeDamage(NewDamage)
												--Gun.Server_Main.Damage:FireServer(HitHumanoid, NewDamage, Player)
												--MarkHit()
												script.MarkHit:FireClient(Player)
											end
										end
									else
										local HitHumanoid = FindFirstClass(HObj.Parent, "Humanoid")
										if HitHumanoid and HitHumanoid.Health > 0 and IsEnemy(HitHumanoid) then
											--MarkHit()
											script.MarkHit:FireClient(Player)
										end
									end
								end
							end)
							E.Parent = game.Workspace
						else
							HitHumanoid = Damage(HitObj, HitPos, HitNorm, Player)
						end
						if S.Penetration > 0 and (not S.GunType.Explosive) then
							PenetrateWall(HitPos, (Bullet.Position - LastPos).unit, HitHumanoid, OriginPos, Bullet, Player)
						else
							Bullet:Destroy()
						end
						break
					else
						LastPos = Bullet.Position
						TotalDistTraveled = TotalDistTraveled + DistTraveled
					end

					Stepped:Wait()
				end
			end)

			if S.BulletTrail and S.TrailTransparency ~= 1 then
				QuickSpawn(function()
					local LastPos2 = nil
					while true do
						if LastPos2 then
							if (not Bullet:IsDescendantOf(game)) then break end
							Bullet.CFrame = CFrame.new(Bullet.CFrame.p, Bullet.CFrame.p + Bullet.Velocity)
							local Trail = Instance.new("Part")
							Trail.BrickColor = S.TrailColor
							Trail.Transparency = S.TrailTransparency
							Trail.Anchored = true
							Trail.CanCollide = false
							Trail.Size = VEC3(1, 1, 1)
							local Mesh = Instance.new("BlockMesh")
							Mesh.Offset = VEC3(0, 0, -(Bullet.Position - LastPos2).magnitude / 2)
							Mesh.Scale = VEC3(S.TrailThickness, S.TrailThickness, (Bullet.Position - LastPos2).magnitude)
							Mesh.Parent = Trail
							Trail.Parent = Gun_Ignore
							Trail.CFrame = CF(LastPos2, Bullet.Position)
							QuickSpawn(function()--delay(S.TrailVisibleTime, function()
								wait(S.TrailVisibleTime)
								if S.TrailDisappearTime > 0 then
									local X = 0
									while true do
										if X == 90 then break end
										if (not Selected) then break end
										local NewX = X + (1.5 / S.TrailDisappearTime)
										X = (NewX > 90 and 90 or NewX)
										local Alpha = X / 90
										Trail.Transparency = NumLerp(S.TrailTransparency, 1, Alpha)
										Stepped:Wait()
									end
									Trail:Destroy()
								else
									Trail:Destroy()
								end
							end)
							LastPos2 = Bullet.Position
						else
							LastPos2 = Main.CFrame.p
						end
						Stepped:Wait()
					end
				end)
			end
		end
	end