Whenever you click on a npc or player with my tool, it sends out a raycast to make sure nothing is blocking the way. However, it outputs the tool’s handle constantly instead of the object blocking it. Does anyone know why?
local gun = script.Parent
--SERVER SCRIPT
script.Parent.MouseEvent.OnServerEvent:Connect(function(player, target)
local gunCast = gun.Handle
local RootPart = target.Parent.HumanoidRootPart
local parameters = RaycastParams.new()
parameters.FilterType = Enum.RaycastFilterType.Blacklist
for i, v in pairs(player.Character:GetChildren()) do
if v:IsA("Part") or v:IsA("MeshPart") then
parameters.FilterDescendantsInstances = {gunCast, v}
end
end
while true do
local GunRay = workspace:Raycast(gunCast.Position, RootPart.Position - gunCast.Position)
print(GunRay)
wait(1)
end
end)
--LOCAL SCRIPT
--REMOTE EVENT REQUIRED
local gun = script.Parent
local localplayer = game.Players.LocalPlayer
local mouse = localplayer:GetMouse()
gun.Activated:Connect(function()
if mouse.Target and mouse.Target.Parent then
if mouse.Target.Parent:FindFirstChildWhichIsA("Humanoid") and mouse.Target.Parent:FindFirstChildWhichIsA("Humanoid").Health > 0 then
local plrTarget = mouse.Target
script.Parent.MouseEvent:FireServer(plrTarget)
end
end
end)
for i, v in pairs(player.Character:GetChildren()) do
if v:IsA("Part") or v:IsA("MeshPart") then
parameters.FilterDescendantsInstances = {gunCast, v}
end
end
No problem, it looked like your code was working it was just getting the descendants of your tools handle, but not the actual handle, same for your body parts (at least all accessories were being registered!)
Quick question, when you print the raycastresult, does it print the InstanceName or the actual name of the part.
For example the result is a part named Hello, would it print as Hello or Part.
Since the result now is just “Part”.
I believe it prints the Instance it has come in contact with, which would probably show up as Part aka its ClassName, with this result you have direct access to its properties