Hey there, so, I’ve been making a client gun script, and while polishing some aspects, I’ve ran into an issue - In the function “Shoot”, the local variable “res” and “intersection” gets the mouse.hit.position and uses a blacklist above it for allies to prevent them from blocking bullets, but mouse.hit ignores collision groups all together and is just set as “Default”, causing bullets to swerve completely off when I’m hovered at allies trying to shoot enemies from behind (Doing so from the head makes the problem much more prevalent and apparent).
I’ve left relevant chunks and context to get my problem across more easily. Help and guidance is appreciated, my problem I assume is the mouse.hit at both “res” and “intersection”. I’m just not sure how I could go about altering the code to fix this problem
local newHighlight = Instance.new("Highlight")
newHighlight.FillColor = Color3.fromRGB(199, 255, 201)
newHighlight.Parent = nil
game.Players.LocalPlayer:GetMouse().TargetFilter = workspace.IgnoreandClearonEndorStart --Ignore dead and effects
local Guncast = RaycastParams.new() --raycast for the bullets
Guncast.FilterType = Enum.RaycastFilterType.Exclude
Guncast.CollisionGroup = "Bullet" --detect parts under the default and player collision group, every limb will be on here except humanoidrootpart
Guncast.IgnoreWater = true
Guncast:AddToFilter(game.Players.LocalPlayer.Character,workspace.IgnoreandClearonEndorStart) --ignore user and effects
local function DrawRecticle() --would constantly be called on every prerender connect when equipped
local viewportResult = workspace.CurrentCamera:ViewportPointToRay(game:GetService("UserInputService"):GetMouseLocation().X, game:GetService("UserInputService"):GetMouseLocation().Y, 0)
local res = workspace:Raycast(viewportResult.Origin, viewportResult.Direction.Unit * 500, Guncast)
local currentRecticleColor = Color3.fromRGB(238, 238, 238)
if res and res.Instance.Parent:FindFirstChild("Humanoid") and res.Instance.Parent.Humanoid.Health > 0 then
if require(game:GetService("ReplicatedStorage").Modules.TeamRegistrations)[game.Players.LocalPlayer.Team.Name][game.Players:GetPlayerFromCharacter(res.Instance.Parent).Team.Name] then
currentRecticleColor = Color3.fromRGB(162, 255, 148) --Ally
else
currentRecticleColor = Color3.fromRGB(161, 45, 45) --Enemy
end
newHighlight.FillColor = currentRecticleColor
newHighlight.Parent = res.Instance.Parent --targetInfo.CharacterModel
return
end
newHighlight.Parent = nil --If nothing or a part not under a character
end
local function Shoot()
local newAlliedParams = RaycastParams.new() --Mousecast
newAlliedParams.FilterType = Enum.RaycastFilterType.Exclude
newAlliedParams.CollisionGroup = "Bullet"
newAlliedParams.IgnoreWater = true
newAlliedParams:AddToFilter(workspace.IgnoreandClearonEndorStart)
for _,member in game.Players:GetPlayers() do
if member.Character.Humanoid.Health > 0 and require(game:GetService("ReplicatedStorage").Modules.TeamRegistrations)[game.Players.LocalPlayer.Team.Name][member.Team.Name] then newAlliedParams:AddToFilter(member.Character)
end
end
local res = workspace:Raycast(script.Parent.Shoot.Position,(game.Players.LocalPlayer:GetMouse().Hit.Position - script.Parent.Shoot.Position).Unit*500, newAlliedParams)
local intersection = res and res.Position or script.Parent.Shoot.Position + (game.Players.LocalPlayer:GetMouse().Hit.Position - script.Parent.Shoot.Position).Unit*500
game:GetService("ReplicatedStorage").Remotes.SpecialEffects:FireServer("BulletVisual", 0.2, (script.Parent.Shoot.Position - intersection).Magnitude, script.Parent.Shoot.Position, intersection, Color3.new(1, 0.690196),0.2)
if res and res.Instance.Parent:FindFirstChild("Humanoid") and res.Instance.Parent.Humanoid.Health > 0 then
print("Enemy hit")
end
end