2017-05-30 63 views
0

我在我的遊戲中製作了一個效果,它可以滾動選擇某個選項,然後在一個選項中減速停止。效果沒有顯示在guis上

有4個屏幕,我希望每個人都能同時播放效果,所有的guis同時出現,但效果永遠不會播放。我標誌着確實在下面的代碼塊中的作用的代碼部分:

message.chooseduel = function(spins) 
    local lobby=workspace.Lobby 
    local screens=lobby.Screens 
    local n1,n2 
    for _, screen in pairs(screens:GetChildren()) do 
     local gui=screen.SurfaceGui 
     local ds=gui.DuelScreen 
     gui.Enabled=true 
     for i, v in pairs(ds.Container:GetChildren()) do 
      local ll 
      local lastpicked  
      local t = ds.Container:GetChildren() 
      local menuItems = #t -- number of menu items 
      local repeats = 1 -- Repeated 
      for R = 65 + spins, 1, -1 do 
       ll = t[repeats] 
       if ll:IsA("GuiObject") then 
        --**effect**-- 
        local newgui = coroutine.wrap(function() 
        print("HI!") 
        ll.BackgroundColor3=Color3.fromRGB(130, 125, 56) 
        wait(R^-.7*.7) -- 
        ll.BackgroundColor3=ll.BorderColor3 
        repeats = repeats % menuItems + 1 
        end) 
        newgui() 
        --**effect**-- 
       end 
      end 
      ll = t[repeats] 
      ll.BackgroundColor3=Color3.fromRGB(230, 225, 156) 
      n1=string.sub(ll.n1.Image,64) 
      n2=string.sub(ll.n2.Image,64) 
      print("Returning:",n1,n2) 
     end 
    end 
    wait(2) 
    return {n1,n2} 
end 

回答

1

希望這有助於:

message.chooseduel = function(spins) 
    spins = math.ceil(spins) -- just making sure. 
    local lobby=workspace.Lobby 
    local screens=lobby.Screens 
    local n1,n2 
    for _, screen in pairs(screens:GetChildren()) do 
     local gui=screen.SurfaceGui 
     local ds=gui.DuelScreen 
     gui.Enabled=true 
     spawn(function() -- I think this is where the coroutine/async function should start 
      local ll 
      local lastpicked -- Variable not used 
      local t = ds.Container:GetChildren() 
      local numMenuItems = #t -- number of menu items 
      local current = 1 -- Repeated 
      print("HI!") 
      for R = 65 + spins, 1, -1 do 
       ll = t[current] 
       if ll:IsA("GuiObject") then 
        ll.BackgroundColor3=Color3.fromRGB(130, 125, 56) 
        wait(R^-.7*.7) -- 
        ll.BackgroundColor3=ll.BorderColor3 
        current = current % numMenuItems + 1 
       end 
      end 
      print("BYE!") 
      ll = t[current] 
      ll.BackgroundColor3=Color3.fromRGB(230, 225, 156) 
      n1=string.sub(ll.n1.Image,64) -- um... Interesting. wait what? 
      n2=string.sub(ll.n2.Image,64) 
      print("Returning:",n1,n2) 
     end) 
    end 
    wait(2) 
    return {n1,n2} 
end 

我不知道我完全讓你在做什麼在這裏或如何設置事物,但一般來說,您應該嘗試將協程/衍生函數移至循環的外部。