So I am trying to make a knife system which you will be able to throw it.
I am trying to make it so that you have to hold right click then you can press left click to be able to throw it. When the player holds right click I have made it so that an animation plays and when the player doesn't it stops. I only want it to work when the player equips it. For some reason it it still work. The inputs don't stop. Please help :)
Code:
local player = game.Players.LocalPlayer local UserInputService = game:GetService("UserInputService") local anim = script:WaitForChild("ThrowIdleAnimation") local throwing = false local char = player.Character local anim1 = char.Humanoid:LoadAnimation(anim) local tool = script.Parent tool.Equipped:Connect(function() UserInputService.InputBegan:Connect(function(input) if input.UserInputType == Enum.UserInputType.MouseButton2 then throwing = true anim1:Play() end end) UserInputService.InputEnded:Connect(function(input) if input.UserInputType == Enum.UserInputType.MouseButton2 then throwing = false anim1:Stop() end end) end)