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

How to make input system stop when tool is unequipped?

Asked by 3 years ago
Edited 3 years ago

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)

Answer this question