如何删除roblox中所有克隆的gui



我正在创建一个舞蹈表演游戏,我想在每轮比赛前在列表中显示玩家的姓名和顺序。我正在使用克隆,它为每个玩家创建一个新的标签。我的问题是,克隆的名单在第一轮之后不会被删除,玩家的名字也会重复。这是我的代码

contList.OnClientEvent:Connect(function(Contestants)  ---Remote event in local script
for i=1,#Contestants do
nameList  = script.Parent.List.plrsList.nameList:Clone()
nameList.Parent = script.Parent.List.plrsList
nameList.Name = Contestants[i].Name    
nameList.nList.Text = Contestants[i].Name     --players name
seqNo = script.Parent.List.sequence.seqNo:Clone()
seqNo.Parent = script.Parent.List.sequence
seqNo.Name =i                                 --sequence number
seqNo.sequence.Text = i
List = script.Parent.List
end
List.Visible = true
wait(10)
List.Visible = false
for i=1,#Contestants do
nameList:Remove()
seqNo:Remove()
end
end)

您的问题是,当您清理东西时,nameListseqno变量只指向您添加到列表中的最后一个项目,而不是删除您添加的所有项目。

有几种不同的方法可以去除它们,但我会推荐给

  1. 创建一个类似Frame的空容器
  2. 创建新的TextLabel时,将其作为该Frame的子级
  3. 当您准备好清理时,只需删除Frame,即可同时删除所有子项

看起来是这样的:

contList.OnClientEvent:Connect(function(Contestants)  ---Remote event in local script
-- find some UI elements
local list = script.Parent.List
local playersList = list.plrsList
local playerNameList = playersList.nameList
local sequence = list.sequence
local sequenceNumber = sequence.seqNo
-- 1. create an empty container for all players
local container = Instance.new("Frame")
container.Size = UDim2.new(1, 0, 1, 0)
container.Position = UDim2.new(0, 0, 0, 0)
container.BackgroundTransparency = 1.0
local layout = Instance.new("UIListLayout", container)
layout.SortOrder = Enum.SortOrder.Name
-- 1a. create a container for player names
local playerContainer = container:Clone()
playerContainer.Parent = playersList
-- 1b. create a container for player numbers
local sequenceContainer = container:Clone()
sequenceContainer.Parent = sequence
-- 2. create an entry for every player, and put them into their containers
for i = 1, #Contestants, 1 do
local nameList  = playerNameList:Clone()
nameList.Name = Contestants[i].Name
nameList.nList.Text = Contestants[i].Name
nameList.Parent = playerContainer
local seqNo = sequenceNumber:Clone()
seqNo.Name = tostring(i)
seqNo.sequence.Text = tostring(i)
seqNo.Parent = sequenceContainer
end
-- momentarily show the list
list.Visible = true
wait(10)
list.Visible = false
-- 3. clean up by deleting the containers
playerContainer:Destroy()
sequenceContainer:Destroy()
end)

相关内容

  • 没有找到相关文章

最新更新