Why does this Local Script run fine but does not work with KeyDown function?
This local script works fine with everything but then when the keydown function comes it is like the script skipped over it and continued on with everything else every time.
01 | local tool = script.Parent |
03 | local player = game.Players.LocalPlayer |
04 | local character = player.Parent |
10 | local handle = tool:WaitForChild( "Handle" ) |
11 | local event = tool:WaitForChild( "RemoteEvent" ) |
12 | local firesound = handle:WaitForChild( "FireSound" ) |
18 | function checkintangible(hit) |
19 | if hit and hit ~ = nil then |
20 | if hit:IsDescendantOf(tool.Parent) or hit.Name = = "Handle" or string.lower(string.sub(hit.Name, 1 , 6 )) = = "effect" then |
27 | function castray(startpos, vec, length, ignore, delayifhit) |
28 | local hit, endpos 2 = game.Workspace:FindPartOnRay(Ray.new(startpos, vec * length), ignore) |
30 | if checkintangible(hit) then |
31 | hit, endpos 2 = castray(endpos 2 + (vec * . 01 ), vec, length - ((startpos - endpos 2 ).magnitude), ignore, delayifhit) |
37 | tool.Equipped:connect( function (mouse) |
41 | mouse.Button 1 Down:connect( function () |
42 | local humanoid = tool.Parent:FindFirstChild( "Humanoid" ) |
43 | local head = tool.Parent:FindFirstChild( "Head" ) |
44 | local torso = tool.Parent:FindFirstChild( "Torso" ) |
45 | if check and humanoid and humanoid.Health > 0 and head and torso then |
51 | local vec = (mouse.Hit.p - head.Position).unit |
52 | local hit ,endpos = castray(head.Position, vec, range, tool.Parent) |
54 | event:FireServer( "Fire" , endpos, hit) |
63 | mouse.KeyDown:connect( function (key) |
66 | for _, part in pairs (character:GetChildren()) do |
67 | if part.ClassName = = "Torso" then |
69 | elseif part.ClassName = = "Head" then |
71 | elseif part.ClassName = = "Right Arm" then |
73 | elseif part.ClassName = = "Left Arm" then |
75 | elseif part.ClassName = = "Right Leg" then |
77 | elseif part.ClassName = = "Left Leg" then |
86 | tool.Unequipped:connect( function () |