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.