Sorry for the late reply, I searched a gun kit that has exactly the bullet tracers I need, but I can’t seem to get it work on my game, of course, I didn’t copy and paste it.
The error on the output is: attempt to perform arithmetic (sub) on Vector3 and nil
Code:
function module.create(Origin, Character, Direction, Speed)
local CameraCFrame = workspace.CurrentCamera.CFrame
local t0, p0, v0, av0, rot0, offset
local Connection
local Wind
local BulletVisual = game.ReplicatedFirst.VisualBullet:Clone()
local Beam = BulletVisual:WaitForChild("Beam")
BulletRaycastParam.FilterDescendantsInstances = {BulletVisual, workspace.Projectiles, Character, workspace.Camera}
local Lifetime = 0
local Hits = BulletVisual.Hits
BulletVisual.CFrame = Origin
local StartCF = BulletVisual.CFrame
local Direction = Origin.LookVector
local Position = StartCF.Position
local Attachment0 = BulletVisual.Beam.Attachment0
local Attachment1 = BulletVisual.Beam.Attachment1
BulletVisual.Parent = workspace.Projectiles
local w0 = BulletVisual.CFrame.Position - Origin.Position
local Time = os.clock()
local t1, p1, v1 = os.clock(), CFrame.new():PointToObjectSpace(CameraCFrame.Position, w0)
t0 = os.clock()
av0 = Vector3.new(3, 0, 0)
rot0 = BulletVisual and (BulletVisual.CFrame - BulletVisual.CFrame.p) or CFrame.new()
offset = Vector3.new()
local function update(w2, t2, size, bloom, brightness, DT)
local t2 = os.clock()
local p2 = CFrame.new():PointToObjectSpace(CameraCFrame.Position, w2)
local v2
if t0 then
v2 = 2 / (t2 - t1) * (p2 - p1) - (p2 - p0) / (t2 - t0) "problem"
else
v2 = (p2 - p1) / (t2 - t1)
v1 = v2
end
t0, v0, p0 = t1, v1, p1
t1, v1, p1 = t2, v2, p2
local dt = t1 - t0
local m0 = v0.Magnitude
local m1 = v1.Magnitude
Beam.CurveSize0 = dt / 3 * m0
Beam.CurveSize1 = dt / 3 * m1
Attachment0.Position = CameraCFrame * p0
Attachment1.Position = CameraCFrame * p1
if m0 > 1.0E-8 then
Attachment0.Axis = CFrame.new():VectorToWorldSpace(CameraCFrame.Position, v0 / m0)
end
if m1 > 1.0E-8 then
Attachment1.Axis = CFrame.new():VectorToWorldSpace(CameraCFrame.Position, v1 / m1)
end
local dist0 = -p0.z
local dist1 = -p1.z
if dist0 < 0 then
dist0 = 0
end
if dist1 < 0 then
dist1 = 0
end
local w0 = size + bloom * dist0
local w1 = size + bloom * dist1
local l = ((p1 - p0)*Vector3.new(1, 1, 0)).Magnitude
local tr = 1 - 4 * size * size / ((w0 + w1) * (2 * l + w0 + w1)) * brightness
Beam.Width0 = w0
Beam.Width1 = w1
Beam.Transparency = NumberSequence.new(tr)
end
Connection = RunService.RenderStepped:Connect(function(Delta)
if BulletVisual then
Direction *= Speed/2
BulletVisual.Position += Direction
update((BulletVisual.Position - Origin.Position), Time, 0.1, 0.005, 400, Delta)
end
local RaycastResult = workspace:Raycast(BulletVisual.Position, Direction, BulletRaycastParam)
if RaycastResult ~= nil then
local Inst = RaycastResult.Instance
local RayPos = RaycastResult.Position
local RayNormal = RaycastResult.Normal
if Inst.Parent:FindFirstChildWhichIsA("Humanoid") then
BulletVisual:Destroy()
if Connection then
Connection:Disconnect()
Connection = nil
end
else
BulletVisual:Destroy()
if Connection then
Connection:Disconnect()
Connection = nil
end
Hits.Value += 1
if Hits.Value == 1 then
--local reflect = (Direction - (2 * Direction:Dot(RayNormal) * RayNormal))
--local reflect = reflect((RayPos - BulletVisual.CFrame.Position), RayNormal)
--Direction = reflect
if BulletVisual then
BulletVisual:Destroy()
if Connection then
Connection:Disconnect()
Connection = nil
end
end
end
end
end
Lifetime += Delta
if (Lifetime > 3.5) then
BulletVisual:Destroy()
if Connection then
Connection:Disconnect()
Connection = nil
end
end
end)
return BulletVisual
end