Raycasting detection is bugging out

So I have been working on this viewmodel system for quite a little bit. I get it going pretty well and decided to make a shooting system. Turns out something as simple as this has turned into a real big nightmare for me.

It has done nothing but causing me trouble, for the raycasts seem to have a mind of it’s own.
It will not detect the baseplate sometimes, and when it does, it will not detect any humanoid/character at all.

local Origin = Framework.Viewmodel.Muzzle.Position

						local Direction = (Mouse.Hit.p - Origin)

						Params.FilterDescendantsInstances = {Framework.Viewmodel, Character}

						local Result = game.Workspace:Raycast(Framework.Viewmodel.Muzzle.Position, Direction * 500, Params)

						-- PART CHECK --

						local Part_Hit

						if Result ~= nil then

							Part_Hit = Result.Instance

						end

						-- HUMANOID CHECK --

						local IsHumanoid

						local Headshot

						if Result then
							
							print("Hit!", Result.Instance.Name)

							if Result.Instance.Name == "Handle" then

								IsHumanoid = Result.Instance.Parent.Parent:FindFirstChild("Humanoid")

							elseif Result.Instance.Parent:FindFirstChild("Humanoid") then

								IsHumanoid = Result.Instance.Parent:FindFirstChild("Humanoid")

								if Result.Instance.Name == "Head" then

									Headshot = true

								end

							end

If anymore information is needed, please let me know and i will provide it.

For starters, it’d be great if I knew what your question was. The only thing I can assume is that you want to detect both the baseplate and characters at the same time, which, as far as I’m concerned, isn’t possible. At least, not without some wildly inefficient engineering.

Sorry I wasn’t clear in my question, and no I do not want both to be detected. I am just confused how a normal raycasting system isn’t detecting anything sometimes. Sometimes I shoot the baseplate, it prints the raycast result and other times it just doesn’t at all.

I can’t get a video of all examples but this is the best I got wit h the output printing out what it hits.

Nevermind, I found out the issue. The Humanoidrootpart of the viewmodel was not anchored.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.