-
What do you want to achieve? Keep it simple and clear!
I’m trying to create a bullet trail effect for a pistol I am making but its very delayed and I’m trying to figure out how to speed it up. -
What is the issue? Include screenshots / videos if possible!
I’ve gotten the effect to work so far, but the problem is its very delayed(Look at media I have included)
Loud Audio Warning
As you can see when I’m standing still the effect looks perfectly fine but when I move it’s very delayed.
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve tried shortening the code to make it faster but the delayed effect persisted I’ve tried looking for people with similar issues but came up with nothing helpful.
Main code–
function particle(part1, part2, result)
local magnitude = math.abs((part1.Position - part2.Position).Magnitude)
local trailpart = script.Parent.PremadePart:Clone()
trailpart.Parent = workspace
trailpart.CFrame = CFrame.lookAt(part1.Position, part2.Position)
local pos = (part1.Position + part2.Position)/2
trailpart.Position = pos
trailpart.Size = Vector3.new(trailpart.Size.X, trailpart.Size.Y, magnitude)
end
This main code takes in 1. The part the effect will come from(the tip of the gun) part 2. The part it will hit and the result is the result of a raycast that the gun uses to determine what it hit. The whole goal of the code is to take the effect part and to resize its position and orientation to create the shooting effect.
This is located in the server script that is mentioned later
tool.Equipped:Connect(function()
local char = tool.Parent
local plr = game.Players:GetPlayerFromCharacter(char)
local mouse = plr:GetMouse()
local idle_animation_track = tool.Parent.Humanoid:LoadAnimation(tool.Idle)
idle_animation_track:Play()
tool.Activated:Connect(function()
if debounce == true and tool.Ammo.Value > 0 and reloading == false then
debounce = false
remote_event:FireServer(mouse.Hit.Position)
local shoot_animation_track = tool.Parent.Humanoid:LoadAnimation(tool.Shoot)
shoot_animation_track:Play()
wait(.25)
debounce = true
else
local value = "other"
tool.Reload:FireServer(value)
end
end)
-excerpt from a local script where the tool is activate and where the position the mouse clicked on is passed to a server script via a remote event.
remote_event.OnServerEvent:Connect(function(plr, mouse_pos)
local origin = tool.ShootPart.Position
local direction = mouse_pos - origin
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {tool.Parent, tool.Parent:GetChildren(), tool.Handle, tool.ShootPart}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.IgnoreWater = true
local ray_result = workspace:Raycast(origin, direction * 10, raycastParams)
particle(script.Parent.ShootPart, ray_result, ray_result)
-excerpt from the server script that receives the mouse position and creates the raycast.
You can see the particle effect being created by the function in the last line, passing along those 3 variables.