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()