Bullet Tracer and TweenService

Facing an issue where my Bullet Tracer; a Beam, is not going back to its original position. The script basically tells the Attachment.Parent the location and moves it using tween service.

My goal is to make the Beam move towards the tween position and teleport back to its original position after the tween is completed, but for some reason it is not working.

Script:

local Point = tool.Handle.Point
		local PointLookVector  = Point.CFrame.LookVector
		
		local RaycastParams = RaycastParams.new()
		RaycastParams.FilterDescendantsInstances = {tool.Parent}
		RaycastParams.FilterType = Enum.RaycastFilterType.Exclude


		local Point = tool.Handle.Point
		local doDmgRE = tool:WaitForChild("DoDamage")

		local RaycastResult = workspace:Raycast(Point.Position, PointLookVector * 500, RaycastParams)



local function BulletRay()
			

			
			if RaycastResult == nil then 
				print("Jammed")
				
			else
				
				local RayDistance = RaycastResult.Distance
				local RayPosition = RaycastResult.Position
				
				print(RayPosition)
				local Silencer = tool.Handle.Silencer
				local bp0 = Silencer.beamPart0
				local bp1 = Silencer.beamPart1
				local beam = Silencer.Beam
				
			
				beam.Enabled = true
				
				
				local TweenService = game:GetService("TweenService")
				local Tweeninfo = TweenInfo.new(0.1 , Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
				
				local tween = TweenService:Create(bp1, Tweeninfo, {Position = RayPosition})
				
				
				tween:Play()
				
				if tween.Completed then 
					bp1.Position = bp0.Position
				end
			
			end
			
		end
		
		BulletRay()

1 Like

After the script passes over this if statement, even if the tween finishes, it won’t update the statement. To fix this you’d have to either implement a task.wait() or use the .Completed event. Although using the event proves to be the more consistent option.

First Option:

task.wait(Tweeninfo.Time)
-- Reset the position

Seccond Option:

tween.Completed:Connect(function()
  -- reset the position
end)

As far as I can tell that is the only issue! Hope this helps!

1 Like

Yeah it works…just need to work on some improvements on the tracer effect. Thanks

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.