尝试使用 'Value' 索引 nil

Attemp to index nil with 'Value'

我打算做一个切换器。这意味着当您装备该工具时,切换器(服务器脚本)将打开文件夹内的 body 系统,并且在 ServerScriptService 中我将它们全部禁用,.这是切换器代码。

local Tool = script.Parent
local SSS = game.ServerScriptService:WaitForChild("CombatFolder")

function onEquippedLocal()
    SSS:WaitForChild("CanAttack").Disabled = false
    SSS:FindFirstChild("M1").Disabled = false

    SSS:FindFirstChild("M2").Disabled = false

end

function onUnequippedLocal()
    SSS:WaitForChild("CanAttack").Disabled = true
    SSS:FindFirstChild("M1").Disabled = true

    SSS:FindFirstChild("M2").Disabled = true

end

Tool.Equipped:connect(onEquippedLocal)
Tool.Unequipped:connect(onUnequippedLocal)

这是我装备工具时的输出

  10:50:22.732  Players.TeemoHoang_2008.Backpack.SwordCombat.M2:15: attempt to index nil with 'Value'  -  Client - M2:15
  10:50:22.732  Stack Begin  -  Studio
  10:50:22.732  Script 'Players.TeemoHoang_2008.Backpack.SwordCombat.M2', Line 15  -  Studio - M2:15
  10:50:22.732  Stack End  -  Studio
  10:50:24.099  Players.TeemoHoang_2008.Backpack.SwordCombat.newCombat:54: attempt to index nil with 'Value'  -  Client - newCombat:54
  10:50:24.099  Stack Begin  -  Studio
  10:50:24.099  Script 'Players.TeemoHoang_2008.Backpack.SwordCombat.newCombat', Line 54  -  Studio - newCombat:54
  10:50:24.099  Stack End  -  Studio

这里是工具中M2(本地脚本)启动报错时的函数

script.Parent.Equipped:Connect(function()
    uis.InputBegan:Connect(function(input)
        if input.UserInputType == Enum.UserInputType.MouseButton2  then
            if debounce == false and char:FindFirstChild("CanAttack").Value == true and char:FindFirstChild("Stun") == nil and char:FindFirstChild("eStun") == nil and char:FindFirstChild("BlockBreak") == nil and char:FindFirstChild("IsBlocking") == nil then
                if  char:FindFirstChild("SwordCombat") then
                    local tool =  char:FindFirstChild("SwordCombat")
                    if tool:IsA("Tool")then
                        debounce = true

                        remote:FireServer() 
                    end
                end     
            end
        end
    end)
end)

这是工具里面newCombat(localscript)的错误行

script.Parent.Activated:Connect(function()
    if char:FindFirstChild("CanAttack").Value == true and char:FindFirstChild("Stun") == nil and char:FindFirstChild("eStun") == nil and char:FindFirstChild("IsBlocking") == nil and char:FindFirstChild("BlockBreak") == nil then

我曾尝试禁用 newCombat 和 M2,并在与 body 系统同时装备工具时启用它,但当我这样做时。 M2 只显示错误,但一切仍然无效。请帮忙!

错误很明显。您正在尝试使用 Value 索引一个 nil 值,因此 char:FindFirstChild("CanAttack") returns nil.

Instance:FindFirstChilde(name) returns 如果没有 child 具有给定名称,则为零。

找出为什么没有这样的 child 或检查是否确实存在 child,然后再尝试对其进行索引。