Roblox Lua: 随机错误?

我的目标是制作一个变量(_G.rownedB 和 _G.gownedB),每秒将 _G.RPoints 或 _G.GPoints 的点数增加1,直到其中一个达到了1200点。不幸的是,它似乎没有正确地运作,而是根本没有工作,当我捕捉点时,点gui文本(_G.News.Text)不起作用。我的错误是什么?

-- Script by Dropdatderp
capturing = nil
_G.rownedB = false
_G.gownedB = false
neutral = true
function get_player(part)
    for _, player in ipairs(game.Players:GetPlayers()) do
        if part:IsDescendantOf(player.Character) then
            return player
        end
    end
end
function onTouched(part)
local h = part.Parent:findFirstChild("Humanoid")
if h ~= nil then
    if _G.gownedB或neutral == true then
        capturing = true
        _G.News.Text ="突袭者正在占领B点!"
        wait(10)
        _G.News.Text = "突袭者已经占领了B点。"
        capturing = nil
        _G.rownedB = true
        _G.gownedB = false
        neutral = false
    end
    elseif _G.rownedB或neutral == true then
        local player = get_player(part)
        if player:IsInGroup("901313") then
            capturing = true
            _G.News.Text = "防御者正在占领B点!"
            wait(10)
            _G.News.Text = "防守者已经占领了B点。"
            capturing = nil
            _G.rownedB = false
            _G.gownedB = true
            neutral = false
            repeat
                wait(1)
                _G.RPoints = _G.RPoints + 1
            until _G.RPoints或_G.GPoints == 1200
        end
    end
end
repeat
script.Parent.Touched:connect(get_player)
script.Parent.Touched:connect(onTouched)
until _G.GPoints == 1200_G.RPoints == 1200
点赞
用户2858170
用户2858170

首先,检查你的条件语句。

这个代码块是你想要的吗?

if h ~= nil then
  if _G.gownedB or neutral == true then

  end
elseif _G.rownedB or neutral == true then

  if player:IsInGroup("901313") then

  end

end

或者是这个?

if h ~= nil then
  if _G.gownedB or neutral == true then

  elseif _G.rownedB or neutral == true then
    if player:IsInGroup("901313") then

    end

  end
end

请确保你理解这行代码的作用:

script.Parent.Touched:connect(onTouched)

并且问问自己是否有必要多次调用它。

你会永远停留在重复的直到语句里吗?

你有什么被遗漏了吗?

repeat
  wait(1)
  _G.RPoints = _G.RPoints + 1
until _G.RPoints or _G.GPoints == 1200

这段代码有任何有用的东西吗?

仔细阅读你的代码,问问自己你想做什么,以及正在发生什么。画一个简单的流程图或决策树,并运行几个案例...

2016-09-07 15:40:46