我在我的游戏中制作了一个效果,它会滚动一些选项并在一个选项上减速停止。
有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
答案 0 :(得分: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
我不确定我完全了解你在这里做了什么或者你是如何设置的,但一般来说你应该尝试将协同程序/衍生函数移动到循环的外部。