首页 文章

Roblox Lua:随机错误?

提问于
浏览
0

我的目标是创建一个变量(_G.rownedB和_G.gownedB),每1秒向_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 or neutral == true then
        capturing = true
        _G.News.Text = "Raiders are taking Point B!"
        wait(10)
        _G.News.Text = "Raiders have taken Point B."
        capturing = nil
        _G.rownedB = true
        _G.gownedB = false
        neutral = false
    end
    elseif _G.rownedB or neutral == true then
        local player = get_player(part)
        if player:IsInGroup("901313") then
            capturing = true
            _G.News.Text = "Defenders are taking Point B!"
            wait(10)
            _G.News.Text = "Defenders have taken Point B."
            capturing = nil
            _G.rownedB = false
            _G.gownedB = true
            neutral = false
            repeat
                wait(1)
                _G.RPoints = _G.RPoints + 1
            until _G.RPoints or _G.GPoints == 1200
        end
    end
end
repeat
script.Parent.Touched:connect(get_player)
script.Parent.Touched:connect(onTouched)
until _G.GPoints == 1200 or _G.RPoints == 1200

1 回答

  • 0

    首先,检查您的if语句 . 这就像你想要的那样吗?

    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
    

    这有用吗?

    仔细阅读您的代码,问问自己您想做什么以及发生了什么 . 绘制一个简单的流程图或决策树,并播放几个案例......

相关问题