Really weird bug starts to fix itself randomly

  1. What do you want to achieve?
    I wanted to create a bullet tracer system. It would work by creating a beam and moving the origin attachment to the end attachment with a tween.

  2. What is the issue?
    When I shoot the gun, the origin attachment suddenly goes into the abyss??? I looked into the code of my tracer event, but it doesn’t seem to be the issue.

local enabled												= true
local beamLifetime											= .1
local beamDeleteTime										= .25
local info													=, Enum.EasingStyle.Linear, Enum.EasingDirection.In)

local function unpackNewClone(color: Color3)
	local newTracer = BaseTracer:Clone()
	local source, point = newTracer:WaitForChild("origin"), newTracer:WaitForChild("end")
	local beam = newTracer:WaitForChild("Beam")
	source.Parent = tracerPart
	point.Parent = tracerPart
	beam.Parent = tracerPart
	return source, point, beam

BulletEvent.OnClientEvent:Connect(function(origin: Vector3, point: Vector3, color: Color3)
	if not enabled then
	tracerPart.Position = origin
	local source, dest, beam = unpackNewClone(color)
	source.WorldCFrame =, point)
	dest.WorldPosition = point
	local currrentTween = TweenService:Create(source, info, {WorldPosition = point})
	Debris:AddItem(source, beamDeleteTime)
	Debris:AddItem(dest, beamDeleteTime)
	Debris:AddItem(beam, beamDeleteTime)

But then, if you wait a few minutes it suddenly starts to fix itself??? I think the problem is with the viewmodel’s bopping. I tested standing still and the position is changing, so I think that’s the problem. The problem is that, I don’t understand any of the math with the viewmodel bopping.

--Edited script of the viewmodel handler
local SpringModule				= require(ClientModules:WaitForChild("SpringModule"))

local function Bob(addition)
	return math.sin(tick() * addition * 1.3) * 0.5

local function update()
	LookUpDown:FireServer(mouse.Hit.Position, Camera.CFrame.Position)

local function setArmsToCam(dt: number)
	if not primaryPart then
	local Delta = UserInputService:GetMouseDelta()
	swaySpring:shove(, Delta.Y/500, 0))
	bobSpring:shove(, Bob(10), Bob(5)) / 10 * (primaryPart.Velocity.Magnitude) / 10)
	local UpdatedSway = swaySpring:update(dt)
	local UpdatedBob = bobSpring:update(dt)
	local cameraCframe = (Camera.CFrame*cameraOffset)
	Arms:SetPrimaryPartCFrame(cameraCframe*, UpdatedSway.Y, 0)*, UpdatedBob.Y, 0)

--Current spring module I'm using:
-- Constants

local ITERATIONS	= 8

-- Module

local SPRING	= {}

-- Functions 

function, mass, force, damping, speed)

	local spring	= {
		Target		=;
		Position	=;
		Velocity	=;

		Mass		= mass or 5;
		Force		= force or 50;
		Damping		= damping or 4;
		Speed		= speed  or 4;

	function spring.getstats(self)
		return self.Mass, self.Force, self.Damping, self.Speed

	function spring.changestats(self, mass, force, damping, speed)
		self.Mass = mass or self.Mass
		self.Force = force or self.Force
		self.Damping = damping or self.Damping
		self.Speed = speed or self.Speed

	function spring.shove(self, force)
		local x, y, z	= force.X, force.Y, force.Z
		if x ~= x or x == math.huge or x == -math.huge then
			x	= 0
		if y ~= y or y == math.huge or y == -math.huge then
			y	= 0
		if z ~= z or z == math.huge or z == -math.huge then
			z	= 0
		self.Velocity	= self.Velocity +, y, z)

	function spring.update(self, dt)
		local scaledDeltaTime = dt * self.Speed / ITERATIONS
		for i = 1, ITERATIONS do
			local iterationForce= self.Target - self.Position
			local acceleration	= (iterationForce * self.Force) / self.Mass

			acceleration		= acceleration - self.Velocity * self.Damping

			self.Velocity	= self.Velocity + acceleration * scaledDeltaTime
			self.Position	= self.Position + self.Velocity * scaledDeltaTime

		return self.Position

	return spring
-- Return

return SPRING

Here is the viewmodel that im using:
fpa.obj (16.4 KB)

  1. What solutions have you tried so far?
    I have no idea how to solve this. I want to keep the viewmodel bopping into my game tho.
1 Like