Ok so I'm trying to have a server side script create bullet trails, but the local script calls the remote event which creates the trail from the server script. The system works but the only problem I'm having is that the communication delay time isn't consistent. Sometimes the trail will appear instantly but other times the trail will take around 1 second to appear, which can become incredibly annoying. I just want to know if there's any way of keeping this delay time to a minimum or if there's any other method of fixing my problem. Thanks.
Server Code:
local createTrail = script:WaitForChild("createTrail") --createTrail is a remoteEvent
createTrail.OnServerEvent:connect(function(_, Origin, P, gunIgnore, S)
local Trail = Instance.new("Part")
Trail.BrickColor = S.trailSettings.Color
Trail.Transparency = S.trailSettings.Transparency
Trail.Anchored = true
Trail.CanCollide = false
Trail.Size = V3(1, 1, 1)
local Mesh = Instance.new("CylinderMesh")
Mesh.Offset = V3(0, -(P - Origin).magnitude / 2, 0)
Mesh.Scale = V3(S.trailSettings.Thickness, (P - Origin).magnitude, S.trailSettings.Thickness)
Mesh.Parent = Trail
Trail.Parent = gunIgnore
Trail.CFrame = CF(Origin, P) * CFANG(RAD(90), 0, 0)
delay(S.trailSettings.visibleTime, function()
if S.trailSettings.disappearTime > 0 then
local t0 = tick()
while true do
local Alpha = math.min((tick() - t0) / S.trailSettings.disappearTime, 1)
Trail.Transparency = numLerp(S.trailSettings.Transparency, 1, Alpha)
if Alpha == 1 then break end
wait()
end
Trail:Destroy()
else
Trail:Destroy()
end
end)
end)
Local Code:
if S.bulletTrail and S.trailSettings.Transparency ~= 1 then
createTrail:FireServer(Main.CFrame.p, finalP, gunIgnore, S)
end
