Facing a problem where my Raycast
would hit my ParticleEmitter
Part. The script creates a new ParticleEmitter
each time when a gun is fired, this indirectly creates a problem where if you shoot the same spot twice, the ray would hit the ParticleEmitter
part.
How do I fix this issue?
Script:
local Point = tool.Handle.Point
local PointLookVector = Point.CFrame.LookVector
local RaycastParams = RaycastParams.new()
RaycastParams.FilterDescendantsInstances = {tool.Parent}
RaycastParams.FilterType = Enum.RaycastFilterType.Exclude
print(RaycastParams.FilterDescendantsInstances)
local Point = tool.Handle.Point
local doDmgRE = tool:WaitForChild("DoDamage")
local RaycastResult = workspace:Raycast(Point.Position, PointLookVector * 500, RaycastParams)
local RayDistance = RaycastResult.Distance
local RayPosition = RaycastResult.Position
local function HitParticles()
if RaycastResult == nil then
return
else
local emitterpart = Instance.new("Part")
local particle = game:GetService("ReplicatedStorage"):WaitForChild("ParticleEmitter")
emitterpart.Parent = workspace
emitterpart.Anchored = true
emitterpart.Size = Vector3.new(0.5, 1, 0.4)
emitterpart.Orientation = Vector3.new(0, 0.328, 90)
emitterpart.CanCollide = false
emitterpart.Transparency = 1
emitterpart.Name = "emitterpart"
local particleClone = particle:Clone()
particleClone.Parent = emitterpart
local hitsurface = RaycastResult.Instance
local hitsurfaceColor = hitsurface.Color
particleClone.Color = ColorSequence.new(hitsurfaceColor)
emitterpart.Position = RayPosition
local Debris = game:GetService("Debris")
print(RaycastResult.Instance.Name)
Debris:AddItem(emitterpart, 0.5)
end
If the raycast hits the red part, the particles will turn red. The grey part means it hit the Particle Emitter Part.