I want to make trails that appear on both sides of the player and are always ontop of the ground below the player through the use of raycasts but it just ends up like this:
The code:
function TengenVFX.line(args)
for i = 1,2 do
if i == 1 then
local trail = script:WaitForChild("Trail"):Clone()
trail.Parent = workspace.Junk
local weld = Instance.new("Weld",trail)
weld.Part0 = args.Pivot
weld.Part1 = trail
weld.C0 = CFrame.new(-2,0,0)
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = {args.Pivot.Parent,workspace.Junk}
runService.RenderStepped:Connect(function()
for i,v in pairs(trail:GetChildren()) do
if v:IsA("Attachment") then
local result = workspace:Raycast(v.Position,v.CFrame.UpVector * -5,params)
if result then
v.Position = result.Position
end
end
end
end)
else
local trail = script:WaitForChild("Trail"):Clone()
trail.Parent = workspace.Junk
local weld = Instance.new("Weld",trail)
weld.Part0 = args.Pivot
weld.Part1 = trail
weld.C0 = CFrame.new(2,0,0)
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = {args.Pivot.Parent,workspace.Junk}
runService.RenderStepped:Connect(function()
for i,v in pairs(trail:GetChildren()) do
if v:IsA("Attachment") then
local result = workspace:Raycast(v.Position,v.CFrame.UpVector * -5,params)
if result then
v.Position = result.Position
end
end
end
end)
end
end
end