2016-09-06 136 views
0

我的目標是創建一個變量(_G.rownedB和_G.gownedB),每1秒增加_G.RPoints或_G.GPoints 1的點數,直到其中一個點數爲1200。不幸的是,它似乎沒有正常運行,而是完全沒有工作,啓動遊戲,並看到當我捕捉到這一點時,點gui文本(_G.News.Text)不起作用。我的錯誤是什麼?Roblox Lua:隨機錯誤?

-- 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 

回答

0

首先,檢查您的是否是statments。 這就像你想要它嗎?

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 

這會做什麼有用的嗎?

仔細閱讀您的代碼,問問自己想要做什麼以及發生了什麼。畫一個簡單的流程圖或決策樹並播放幾個案例...