I wanted to make a basic fps system, but the raycast that I want the gun to do when shooting is returning nothing when I use parameters, I’m assuming it stops at the excluded parts and ends there?
If I don’t use parameters it would just hit a part of my gun, so should I turn off canquery and cantouch on the gun or is there an issue in my script?
Update: I found out that the problem was I forgot to multiply the lookvector of the camera, but now the issue is that the raycast only detects a single part
Here is the RaycastParams:
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = {tool}
And the code that makes the gun shoot (it’s unfinished so it will only play an animation for now):
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local animator = humanoid:FindFirstChild("Animator")
local cam = game.Workspace.CurrentCamera
local tool = script.Parent
local equipanim = tool.Animations.EquipAK74
local idleanim = tool.Animations.IdleAK74
local walkanim
local inspectanim = tool.Animations.InspectAK74
local fireanim = tool.Animations.FireAK74
local loadequipanim = animator:LoadAnimation(equipanim)
local loadidleanim = animator:LoadAnimation(idleanim)
local loadwalkanim
local loadinspectanim = animator:LoadAnimation(inspectanim)
local loadfireanim = animator:LoadAnimation(fireanim)
UIS.InputBegan:Connect(function(input, gameProcessedEvent)
if input.UserInputType == Enum.UserInputType.MouseButton2 and tool.Parent == char then
aiming = true
elseif input.UserInputType == Enum.UserInputType.MouseButton1 and canshoot == true and tool.Parent == char then
currentlyshooting = true
caninspect = false
print("shot")
repeat
local function recoil()
if canshoot == true and tool.Parent == char then
canshoot = false
loadfireanim:Play()
local castray = game.Workspace:Raycast(tool.Barrel1.Position, cam.CFrame.LookVector, params)
if castray and castray.Instance then
print(castray.Instance)
end
end
end
recoil()
task.wait(RPM)
canshoot = true
until currentlyshooting == false or automatic == false or tool.Parent ~= char
end
end)