部件不会造成损坏,触摸事件

问题描述 投票:0回答:1

我编写了代码但不起作用,我尝试更改代码但没有成功。我怎样才能做到这一点?我想在不对玩家造成伤害的情况下造成伤害。代码在这里:

hitpunch.Touched:Connect(function(hit)
                if hit.Parent:IsA("Model") and hit.Parent.Name == "Boss" and debounceDMG == true then
                    debounceDMG = false
                    hit.Parent.Humanoid.Health -= Player:GetAttribute("Forca")
                    task.wait(.1)
                    debounceDMG = true
                end
            end)
lua roblox luau
1个回答
0
投票

代码中的名称检查和类检查设置不正确。如果你想损坏一个名为

"Boss"
的装备,你可以使用如下代码:

local debounceDMG=true
local part=script.Parent

part.Touched:Connect(function(hit)
    if hit:IsA("Humanoid") and debounceDMG then
       debounceDMG=false
       if hit.Name=="Boss" then
          local heath=hit:FindFirstChild("Heath")
          if heath:IsA("IntValue") then
             heath.Value-=Player:GetAttribute("Forca")
             task.wait(.1)
             debounceDMG=true

这显示了如何根据触摸事件损坏装备或玩家的基本示例。

© www.soinside.com 2019 - 2024. All rights reserved.