Roblox中解除装备触发失败

function Part1()
    wait(0)
    script.Parent.Parent.Humanoid.WalkSpeed = 32
end

function Part2()
    wait(0)
    script.Parent.Parent.Humanoid.Walkspeed = 16
end

script.Parent.Equipped:Connect(Part1)
script.Parent.Unequipped:Connect(Part2)

我想正确触发与解除装备相关的Part2功能,但是失败了。 代码在我想使用的工具中。 我该怎么做?

点赞
用户2860267
用户2860267

此工具是否有或需要手柄?如果您的工具不需要手柄,您可以通过在LocalScript中添加以下内容来使Equipped和Unequipped事件无需任何额外设置即可触发:

script.Parent.RequiresHandle = false

如果您的工具需要一个手柄,请仔细检查Tool的子节点中是否有一个名为“Handle”的Part。

[![工具层次结构的图像。顶级是Tool。里面是一个LocalScript和一个名为Handle的Part。](https://i.stack.imgur.com/bHN76.jpg)](https://i.stack.imgur.com/bHN76.jpg)

2021-06-02 19:12:26
用户15250066
用户15250066

你应该这样获取玩家的 Humanoid

local player = game.Players.LocalPlayer -- 获取本地脚本运行的玩家客户端
local character = player.CharacterAdded:Wait() -- 脚本在游戏运行前就可能开始运行,所以等待人物加载完成后再获取其 humanoid
local humanoid = character:WaitForChild("Humanoid")

这是因为游戏运行时,放在 StarterPlayer 中的工具会被克隆到玩家的背包中,所以你不能使用 script.Parent.Parent.Humanoid。现在,我们可以继续使用原本的脚本:

local player = game.Players.LocalPlayer
local character = player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

function Part1()
   humanoid.WalkSpeed = 32
end

function Part2()
   humanoid.WalkSpeed = 16
end

script.Parent.Equipped:Connect(Part1)
script.Parent.Unequipped:Connect(Part2)
2021-06-03 00:29:56