Heya!
I’m making an assault rifle for a class-based shooter game and there’s an issue I’m trying to solve. The issue being that the raycast abruptly ends whenever hitting an enemies accessory. This basically means that if an enemy is wearing way too many accessories, they can basically negate any damage from the rifle.
--//Tool\--
local Tool = script.Parent
--//Functionality\\--
local PartCache = require(game.ServerScriptService:WaitForChild("PartCache"))
Tool.FireEvent.OnServerEvent:Connect(function(Player, MousePos)
--//Sound
Tool.GripPart.Firing:Play()
--//Setting params so we don't kill yourself with the gun
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {Player.Character}
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
--//Raycasting
local RaycastResult = workspace:Raycast(Tool.FirePart.Position, (MousePos - Tool.FirePart.Position).Unit * 500, raycastParams)
if RaycastResult then
--//Giving the raycast a vizuliser or whatever you call it nsdaabsdnbasdkdabjksadbjds
local Distance = (Tool.FirePart.Position - RaycastResult.Position).Magnitude
local RaycastPart = Instance.new("Part",workspace.Debris)
RaycastPart.Anchored = true
RaycastPart.CanCollide = false
RaycastPart.Material = Enum.Material.Neon
RaycastPart.BrickColor = BrickColor.new("New Yeller")
RaycastPart.Size = Vector3.new(0.1, 0.1, Distance)
RaycastPart.CFrame = CFrame.lookAt(Tool.FirePart.Position, MousePos) * CFrame.new(0, 0, -Distance/2)
game:GetService("Debris"):AddItem(RaycastPart,0.05)
end
--//Damaging
local Hit = RaycastResult.Instance
if Hit then
local Victim = Hit.Parent
local Humanoid = Victim:FindFirstChildWhichIsA("Humanoid")
if Humanoid and Humanoid.Health > 1 then
Humanoid:TakeDamage(15)
print("victim health remaining: "..Victim.Humanoid.Health)
end
end
end)