local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit*30)
local hit, position = game.Workspace:FindPartOnRay(ray, user)
local torso = hit and hit.Parent and hit.Parent:FindFirstChild("Torso")
if torso then
torso.CFrame = CFrame.new(Vector3.new(23, 3, 69))
Please keep in mind I have very basic scripting knowledge.
Hello!
So, I was playing around with a raycasting tutorial, and i made a pretty much working teleporter gun. After testing it a bit, I noticed that tools that players were holding were not ignored, so I opened up the script and prepared to add it to the exception list.
I was planning on adding a check that, if what the raycast hit was a Tool, it'd be ignored, but I ran into a pretty dumb problem.
local hit, position = game.Workspace:FindPartOnRay(ray, user)
Putting the variable for the tool inside the function parameters would be the way to go - but to check if it's a tool, I need to use the hit variable (to check if what it hit is a tool).
Which is, of course, impossible, because the hit variable is being defined where I want to use the hit variable.
I don't even know if I'm making sense right now, but how can I make this work?
And if this isn't the way to make the raycast ignore tools, then what's the correct way?

1 comment
Though I have little experience with raycasting, I recommend using FindPartOnRayWithIgnoreList: http://wiki.roblox.com/index.php?title=Raycasting_Basics#ignoreDescendantsInstance