【问题标题】:"Attempt to compare number with nil" error“尝试将数字与零进行比较”错误
【发布时间】:2021-10-13 20:15:19
【问题描述】:

当我触摸winpad(将触发上面代码的部分)时,它会一直说错误

ServerScriptService.Pads:342: 尝试比较数字

第 342 行是

    if Times < minTime and Timem < 1 and kicks == true and #Boosts == 0 then

这是第 342 行的一些上下文

    local BadgeIDValue = Winpad.KitFolder.Value:FindFirstChild("BadgeID")
    local BadgeID = 0
    if BadgeIDValue then BadgeID = BadgeIDValue.Value end
    local TowerNameValue = Winpad.KitFolder.Value:FindFirstChild("ProperName")
    local TowerName = "Unknown"
    if TowerNameValue then TowerName = TowerNameValue.Value end
    local difficulty = Winpad:GetAttribute("Difficulty")
    local diffcolor = DifficultyDictionaryColors[difficulty]
    local nicelevel = Winpad:GetAttribute("NiceLevel")
    local isSC = Winpad:GetAttribute("isSC")
    local winroom = Winpad:GetAttribute("Winroom")
    local minTime = Winpad:GetAttribute("MinimalTime")
    local CPsReq = Winpad:GetAttribute("CPsRequired")
    local Time:string,Boosts:table<string>? = GetTimerRemote:InvokeClient(Player)
    local checks = ServerStorage:FindFirstChild(Player.Name)
    local towerac = v.Name
    local Times = tonumber(string.sub(Time, 4, 5))
    local Timem = tonumber(string.sub(Time, 1, 2))
    local kicks = script.Switches.KicksEnabled.Value
    if Times < minTime and Timem < 1 and kicks == true and #Boosts == 0 then
        Kick(Player, Time, TowerName, difficulty, Boosts, script.KickReasons.TooEarly.Value) return
    end
    if checks and CPsFound and kicks == true and #Boosts == 0 then
        for i, v in pairs(checks:GetChildren()) do
            if checks:FindFirstChild(towerac.."_"..i) then
                CPCount = CPCount + 1
            end
        end
    end

【问题讨论】:

  • 342 是哪一行?目前我建议打印TimesTimem 看看是否有nil 有可能是你的问题之一,或者两者兼而有之。这可能是由于您如何解析 Time 值。
  • “if Times
  • 是的,在那一行之前添加print(Time, Timem, Times),打印的结果应该告诉你出了什么问题。
  • 好吧,那我明天去看看

标签: lua roblox


【解决方案1】:

minTime 属性可能不存在再次检查 Winpad 属性

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-19
    • 1970-01-01
    • 2017-03-06
    • 1970-01-01
    • 1970-01-01
    • 2013-11-19
    相关资源
    最近更新 更多