检查工具是否已装备

如何在条件语句中确定工具是否已装备?

以下是我的工具“斧头”中的 LocalScript。

local UIS = game:GetService("UserInputService")
local Animation = script.Chop
local Player = game.Players.LocalPlayer
local Character = Player.Character
UIS.InputBegan:Connect(function(input, gameProcessedEvent)
    if input.UserInputType == Enum.UserInputType.MouseButton1 then
        local Player = game.Players.LocalPlayer
        local Character = Player.Character
        local Humanoid = Character:WaitForChild("Humanoid")

        local A = Humanoid:LoadAnimation(Animation)
        A:Play()
    end
end)

原文链接 https://stackoverflow.com/questions/69594053

点赞
stackoverflow用户16938675
stackoverflow用户16938675

你可以创建一个变量来存储布尔值,当工具装备或卸下时改变。

local isEquipped = false

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

Tool.Unequipped:Connect(function()
    isEquipped = false
end)
2021-10-16 08:50:13
stackoverflow用户17177092
stackoverflow用户17177092

当装备时,工具将被纳入角色的下属。因此,您只需编写以下语句:

if Player.Character:FindFirstChild("Axe") ~= nil then

2021-10-17 21:01:07