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

Raycast-Based Gun Doesn't Work?

Asked by 9 years ago

This is a script that is supposed to be in a raycast-based gun. However, when I shoot it, nothing happens. Absolutely nothing. There isn't even anything in the output log.

The exception is when I shoot it skyward, when it registers a "Nil value" error for "Hit." This seems to indicate that it's detecting "Hit", but not doing anything afterwards. How do I fix this?

Here's the code:

01local tool = script.Parent
02local user
03local IgnoreList = {"Handle", "Hat"}
04 
05 
06tool.Equipped:connect(function(mouse)
07 
08   user = {script.Parent:WaitForChild("Handle"), script.Parent:WaitForChild("Handle")}
09 
10   mouse.Button1Down:connect(function()
11 
12      local ray = Ray.new(tool.AimPart.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit*300)
13      local hit, position = game.Workspace:FindPartOnRayWithIgnoreList(ray, user)
14 
15 
View all 46 lines...

Answer this question