Why is part of the script running for the number of times that I right click?
I'm trying to make a script that will grab an npc in which you can throw them afterwards.
001 | if input.UserInputType = = Enum.UserInputType.MouseButton 2 and clicked then |
006 | GrabHitHandling = humanoid.Touched:Connect( function (hit, limb) |
007 | if not isGrabbing then |
010 | if limb.Name = = "RightHand" or limb.Name = = "RightUpperArm" or limb.Name = = "RightLowerArm" then |
012 | target = hit.Parent:FindFirstChild( "Humanoid" ) |
014 | EntInv:InvokeServer(player, target) |
015 | GrabbingVar:FireServer(isGrabbing) |
016 | local d = target.Parent:GetDescendants() |
017 | grabbedAnimate = target:LoadAnimation(grabbed) |
018 | grabbedAnimate.Looped = false |
021 | if desc.Name = = "Head" then |
022 | if not character.RightHand:FindFirstChild( "Weld" ) and not welddb then |
024 | local weld = Instance.new( "Weld" ) |
025 | weld.Part 0 = character.RightHand |
026 | weld.Part 1 = target.Parent.Head |
027 | weld.Parent = character.RightHand |
032 | if not grabbedAnimate.IsPlaying and not grabbingAnimate.IsPlaying then |
034 | grabbedAnimate:Play() |
036 | grabbingAnimate:Play() |
039 | elseif not target and GrabHitHandling then |
040 | GrabHitHandling:Disconnect() |
045 | elseif limb.Name ~ = "RightHand" or limb.Name ~ = "RightUpperArm" or limb.Name ~ = "RightLowerArm" and GrabHitHandling then |
046 | GrabHitHandling:Disconnect() |
051 | elseif not firstrc and isGrabbing then |
053 | local origmotorparent |
055 | local markerdb = true |
056 | local throwBody = throwAnimate:GetMarkerReachedSignal( "ThrowBody" ) |
060 | if throwAnimate.IsPlaying and markerdb then |
062 | local thrBody = throwBody:Connect( function () |
065 | local d = target.Parent:GetDescendants() |
068 | if desc:IsA( "Motor6D" ) then |
070 | origmotorparent = desc.Parent |
071 | socket = Instance.new( "BallSocketConstraint" ) |
072 | local part 0 = desc.Part 0 |
073 | local joint_name = desc.Name |
074 | local attachment 0 = desc.Parent:FindFirstChild(joint_name.. "Attachment" ) or desc.Parent:FindFirstChild(joint_name.. "RigAttachment" ) |
075 | local attachment 1 = part 0 :FindFirstChild(joint_name.. "Attachment" ) or part 0 :FindFirstChild(joint_name.. "RigAttachment" ) |
076 | if attachment 0 and attachment 1 then |
077 | socket.Attachment 0 , socket.Attachment 1 = attachment 0 , attachment 1 |
078 | socket.Parent = desc.Parent |
079 | desc.Parent = game.ServerStorage |
085 | character.RightHand.Weld:Destroy() |
089 | grabbingAnimate:Stop() |
090 | grabbedAnimate:Stop() |
099 | for _, desc in pairs (game.ServerStorage:GetDescendants()) do |
100 | if desc:IsA( "Motor6D" ) then |
102 | desc.Parent = origmotorparent |
110 | print ( "Throw/Grab loop done" ) |
112 | if thrBody and firstrc = = true then |
For some reason, past the
1 | local thrBody = throwBody:Connect( function () |
line, everything is printing for the number of times I have grabbed and thrown in that run. Any ideas?