I’ve been having this issue where I want the Raycast to only detect the Humanoids
Root part. Instead it print outs its accessory’s. How do I make it ignore it?
I don’t want to remove the accessory’s themselves!
local torso = findTarget()
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {NPC}
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
local Head = NPC:WaitForChild('Head')
local hit, hitPosition, hitNormal = workspace:Raycast(Head.Position, Head.CFrame.LookVector * 55, raycastParams)
if torso then
local tweens = tween:Create(HumanoidRootPart,TweenInfo.new(.7,Enum.EasingStyle.Sine,Enum.EasingDirection.Out,0,false,0),
{CFrame = CFrame.lookAt(HumanoidRootPart.Position, torso.Position * Vector3.new(1, 0, 1) + HumanoidRootPart.Position * Vector3.new(0, 1, 0))})
tweens:Play()
if hit and torso then
warn(hit.Instance.Parent)
spawn(function()
local rdm = Animations.Shoot:GetChildren()[math.random(1, #Animations.Shoot:GetChildren())]
local Bullet = game.ServerStorage.MarineStuff.Bullet:Clone()
local Case = game.ServerStorage.MarineStuff.Case:Clone()
Weapon.Barrel.MuzzleDynamicLight.Enabled = true
Weapon.Barrel.MuzzleFlashEffect.Enabled = true
Weapon.Barrel.MuzzleFlashInnerEffect.Enabled = true
Weapon.Barrel.SmokeEffect.Enabled = true
Weapon.Barrel.SparkEffect.Enabled = true
task.wait(.15)
Weapon.Barrel.MuzzleDynamicLight.Enabled = false
Weapon.Barrel.MuzzleFlashEffect.Enabled = false
Weapon.Barrel.MuzzleFlashInnerEffect.Enabled = false
Weapon.Barrel.SmokeEffect.Enabled = false
Weapon.Barrel.SparkEffect.Enabled = false
Bullet.Parent = workspace.Terrain
Case.Parent = workspace.Terrain
Case.CFrame = Weapon:WaitForChild('Chamber').WorldCFrame
Case.CanCollide = true
Weapon["Gun Single Shots 4 (SFX)"]:Play()
Bullet.CFrame = Weapon.Barrel.WorldCFrame
Case.Velocity = Case.CFrame.RightVector * -20 * Vector3.new(1, -3, 1)
Case:FindFirstChildWhichIsA('Sound').Pitch = math.random(9, 11) / 10
Case.Touched:Once(function()
Case:FindFirstChildWhichIsA('Sound'):Play()
end)
if rdm then
Humanoid:LoadAnimation(rdm):Play()
end
Bullet.CFrame = CFrame.lookAt(Weapon:WaitForChild('Barrel').WorldPosition, torso.Position)
for i = 0, 75 do
task.wait()
local originalPosition = Bullet.Position
local finalPosition = originalPosition + Bullet.CFrame.LookVector * 5
Bullet.Position = finalPosition
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {Bullet}
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
local hit, hitPosition, hitNormal = workspace:Raycast(originalPosition, Bullet.CFrame.LookVector * 5, raycastParams)
if hit and hit.Instance.Parent:FindFirstChildWhichIsA('Humanoid') and hit.Instance.Name ~= Bullet.Name then
-- Hit a humanoid
hit.Instance.Parent:FindFirstChildWhichIsA('Humanoid').Health -= math.random(5, 15)
Bullet.Transparency = 1
break
elseif hit and hit.Instance.Name ~= Bullet.Name then
hitPosition = hit.Position
local hitNormal = hit.Normal
local hole = Instance.new("Part", workspace.Terrain)
hole.Size = Vector3.new(0.1, 0.1, 0.01)
hole.Name = 'BulletHole'
hole.Anchored = true
hole.Transparency = 1
local hitOrientation = CFrame.new(Vector3.new(), hitNormal)
hole.CFrame = CFrame.new(hitPosition) * hitOrientation
local offset = 0
hole.Position = hitPosition - hitNormal * offset
local decal = Instance.new("Decal", hole)
decal.Texture = "rbxassetid://3696144972"
decal.Transparency = 0
Bullet.Transparency = 1
task.wait(5)
local fadeDuration = 1
local tweenInfo = TweenInfo.new(fadeDuration, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
local transparencyTween = game.TweenService:Create(decal, tweenInfo, {Transparency = 1})
transparencyTween:Play()
transparencyTween.Completed:Connect(function()
Debris:AddItem(Bullet, 1)
Debris:AddItem(hole, 5)
end)
break
end
end
task.wait()
Debris:AddItem(Bullet, 1)
end)
end
end
end