Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is hit a nil value if i use FindPartOnRayWithIgnoreList?

Asked by
aazkao 787 Moderation Voter
6 years ago

Here is my code in a tool with a handle

tool = script.Parent
handle = tool:WaitForChild("Handle")


tool.Equipped:Connect(function(mouse)
    if mouse then
        mouse.Icon = "rbxassetid://316279304"

tool.Activated:connect(function()
        tool.Firing:Play()
          local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p -  tool.Part.CFrame.p).unit*300)

local hit, position = game.Workspace:FindPartOnRayWithIgnoreList(ray, {game:GetService("Players").LocalPlayer.Character,tool.Handle})
--if i use just FindPartOnRay and ignore only the player it will work and hit will not be a null value??


if hit then
print(hit.Name)
else
print("Error")
end



        end)
    end
end)


0
Ah ok i actually found out its because im printing hit.name and not hit, which is weird because if i use FindPartOnRay and "print hit.name or hit" it works, but for FindPartOnRayWithIgnoreList you cannot print "hit.name", only hit. Well my problem is solved but i really want to understand why this is if anyone can explain to me aazkao 787 — 6y
0
Line 6 is useless. User#19524 175 — 6y
0
yeah forgot to remove it when im editing the code aazkao 787 — 6y

Answer this question