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

How to make this script only work when a certain tool is equipped?

Asked by
exarlus 72
5 years ago

Its a script that plays an animation whenever you click however I have no idea how to make it work on tool equip.

local UserInputService = game:GetService("UserInputService")
local Tool = script.Parent
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")

UserInputService.InputBegan:Connect(function(InputObject)
    if InputObject.UserInputType == Enum.UserInputType.MouseButton1 then
        local Animation = Instance.new("Animation") 
        Animation.AnimationId = "rbxassetid://1630162920" 
        local Track = Humanoid:LoadAnimation(Animation)
        Track:Play()
    end
end)
0
tools have an event called 'Equipped' AdminAyush 10 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
local UserInputService = game:GetService("UserInputService")
local Tool = script.Parent
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")
local Equip = false

UserInputService.InputBegan:Connect(function(InputObject)
    if InputObject.UserInputType == Enum.UserInputType.MouseButton1 then
    if Equip then
            local Animation = Instance.new("Animation") 
            Animation.AnimationId = "rbxassetid://1630162920" 
            local Track = Humanoid:LoadAnimation(Animation)
            Track:Play()
            end
    end
end)

Tool.Equipped:Connect(function()
    Equip = true
end)

Tool.Unequipped:Connect(function()
    Equip = false
end)

I made a debounce called Equip so when you equip it it will be true and when it is unequipped it will be false

Ad

Answer this question