--
local origin = camera.CFrame.Position
local spread = weaponData.Spread
local randSpread = math.random(-weaponData.Spread*100, weaponData.Spread*100)/100
local direction = (CFrame.new(origin, mouse.Hit.Position)*CFrame.Angles(math.rad(randSpread), math.rad(randSpread), 0)).LookVector
--
muzzleEffects(viewmodel, weaponData)
recoil:ShootRecoil(weaponData)
mouse.TargetFilter = camera
distance = (origin - mouse.Hit.Position).Magnitude
weaponData.Ammo -= 1
--
local result = workspace:Raycast(origin, direction * 999, castParams)
if result and result ~= nil then onRayHit(result, direction) end
mouse.TargetFilter = camera
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
I don’t know for certain, but I have experiemented before and found that whenever setting the FilterDescendantsInstances you have to define a new table every time. You cannot edit an existing one. You may try to set it up like this instead.
EDIT: Also, some of your code is redundant, such as the code determining the direction the mouse is pointing in. You can just use the Mouse | Roblox Creator Documentation property. Also, CFrame.new(origin, target) has been deprecated and replaced with CFrame.lookAt(origin, target)
I still have the same issue that I had. I update the ignore list on every shot and I can still hit my own character.
function module:FireNormalShot(viewmodel, weaponData)
--
castParams.FilterDescendantsInstances = {character, workspace.Ignores, camera}
local origin = camera.CFrame.Position
local spread = weaponData.Spread
local randSpread = math.random(-weaponData.Spread*100, weaponData.Spread*100)/100
local direction = (CFrame.new(origin, mouse.Hit.Position)*CFrame.Angles(math.rad(randSpread), math.rad(randSpread), 0)).LookVector
--
muzzleEffects(viewmodel, weaponData)
recoil:ShootRecoil(weaponData)
mouse.TargetFilter = camera
distance = (origin - mouse.Hit.Position).Magnitude
weaponData.Ammo -= 1
--
local result = workspace:Raycast(origin, direction * 999, castParams)
if result and result ~= nil then onRayHit(result, direction) end
end
function module:FireNormalShot(viewmodel, weaponData)
--
local spread = weaponData.Spread
local randSpread = math.random(-weaponData.Spread*100, weaponData.Spread*100)/100
local direction = (mouse.Origin * CFrame.Angles(math.rad(randSpread), math.rad(randSpread), 0)).LookVector
--
muzzleEffects(viewmodel, weaponData)
recoil:ShootRecoil(weaponData)
mouse.TargetFilter = camera
distance = (mouse.Origin.Position - mouse.Hit.Position).Magnitude
weaponData.Ammo -= 1
--
local result = workspace:Raycast(origin, direction * 999, castParams)
if result then onRayHit(result, direction) end
end