I made this map selector Gui that opens up when u enter the elevator. Then it loops through the available maps on the Main Gui and it will look thru replicated storage thru a folder containing the map name and the number of levels. A level template in replicated storage will be cloned and be modified accoring to the configuration values of the level.
It works Fine on the first entry but when I exit the elevator and re-enter this happens…:
this is the map window:
and the level templates will get cloned into this frame:
The Episodes/Levels folder with boolValues to determine if they are the default map or default level (The default map and its corresponding default level with be animated and pre selected the moment you enter the elevator)
Here is the For loop…
for i, map in pairs(MapWindow:GetChildren())do
if map:IsA("ImageButton") then
local DefaultMap
local Button = map
Button.ImageTransparency = 0.67
Button.Highlight.Transparency = 1
Button.Size = UDim2.new(0.65,0,0.65,0)
for i, Values in pairs(ReplicatedStorage.Episodes[Button.Name]:GetChildren())do
if Values:IsA("BoolValue") then
DefaultMap = Values.Parent.Name
end
end
if Button.Name == DefaultMap and not SelectedButton then
for i, level in pairs(gui.LevelSelector.Episodes.EpisodeWindow:GetChildren()) do
if level:IsA("ImageButton") then
level:Destroy()
end
end
SelectedButton = Button
Button.ImageTransparency = 0.2
Button.Highlight.Transparency = 0
StageChange:FireServer("Map", DefaultMap)
coroutine.wrap(function()
TweenService:Create(Button,TweenInfo.new(0.18,Enum.EasingStyle.Back),{Size = UDim2.new(0.85,0,0.85,0)}):Play()
task.wait(0.05)
TweenService:Create(Button,TweenInfo.new(0.12,Enum.EasingStyle.Back),{Size = UDim2.new(0.63,0,0.63,0)}):Play()
task.wait(0.05)
TweenService:Create(Button,TweenInfo.new(0.2,Enum.EasingStyle.Back),{Size = UDim2.new(0.65,0,0.65,0)}):Play()
end)()
for i, Levels in pairs(ReplicatedStorage.Episodes[DefaultMap]:GetChildren())do
if Levels:IsA("Configuration") then
local DefaultLevel
local template = ReplicatedStorage.Episodes.EpisodeTemplate
local newTemplate = template:Clone()
for i, Values in pairs(Levels:GetChildren()) do
if Values:IsA("BoolValue") then
DefaultLevel = Values.Parent.LevelName.Value
end
end
print(DefaultLevel)
newTemplate.LevelName.Text = Levels.LevelName.Value
newTemplate.Name = Levels.LevelName.Value
newTemplate.Number.Text = Levels.Level.Value
newTemplate.LayoutOrder = Levels.LayoutOrder.Value
newTemplate.Parent = gui.LevelSelector.Episodes.EpisodeWindow
if newTemplate.Name == DefaultLevel then
StageChange:FireServer("Level", DefaultLevel)
newTemplate.UIStroke.Transparency = 0
newTemplate.Frame.BackgroundTransparency = 0.9
SelectedLevel = newTemplate
coroutine.wrap(function()
TweenService:Create(newTemplate,TweenInfo.new(0.3,Enum.EasingStyle.Back),{Size = UDim2.new(0,300,0,70)}):Play()
task.wait(0.05)
TweenService:Create(newTemplate,TweenInfo.new(0.12,Enum.EasingStyle.Back),{Size = UDim2.new(0,150,0,45)}):Play()
task.wait(0.05)
TweenService:Create(newTemplate,TweenInfo.new(0.2,Enum.EasingStyle.Back),{Size = UDim2.new(0,200,0,50)}):Play()
end)()
end
newTemplate.Activated:Connect(function()
if SelectedLevel == newTemplate then return end
if SelectedLevel then
SelectedLevel.UIStroke.Transparency = 1
SelectedLevel.Frame.BackgroundTransparency = 0.15
TweenService:Create(newTemplate,TweenInfo.new(0.18,Enum.EasingStyle.Back),{Size = UDim2.new(0.768,0,0.05,0)}):Play()
task.wait()
end
SelectedLevel = nil
task.wait()
SelectedLevel = newTemplate
SelectedLevel.UIStroke.Transparency = 0
SelectedLevel.Frame.BackgroundTransparency = 0.9
StageChange:FireServer("Level", newTemplate.Name)
coroutine.wrap(function()
TweenService:Create(newTemplate,TweenInfo.new(0.3,Enum.EasingStyle.Back),{Size = UDim2.new(0,300,0,70)}):Play()
task.wait(0.05)
TweenService:Create(newTemplate,TweenInfo.new(0.12,Enum.EasingStyle.Back),{Size = UDim2.new(0,150,0,45)}):Play()
task.wait(0.05)
TweenService:Create(newTemplate,TweenInfo.new(0.2,Enum.EasingStyle.Back),{Size = UDim2.new(0,200,0,50)}):Play()
end)()
end)
end
end
end
Button.Activated:Connect(function()
if SelectedButton == Button then return end
if SelectedButton then
SelectedButton.ImageTransparency = 0.68
SelectedButton.Highlight.Transparency = 1
TweenService:Create(SelectedButton,TweenInfo.new(0.2),{Size = UDim2.new(0.65,0,0.65,0)}):Play()
for i, level in pairs(gui.LevelSelector.Episodes.EpisodeWindow:GetChildren()) do
if level:IsA("ImageButton") then
level:Destroy()
end
end
SelectedButton = nil
end
Button.ImageTransparency = 0.2
Button.Highlight.Transparency = 0
--ChangeMap
--player.MapsInfo.ChosenMap.Value = Button.Name
StageChange:FireServer("Map", Button.Name)
coroutine.wrap(function()
TweenService:Create(MapWindow["The Park"],TweenInfo.new(0.18,Enum.EasingStyle.Back),{Size = UDim2.new(0.85,0,0.85,0)}):Play()
task.wait(0.05)
TweenService:Create(MapWindow["The Park"],TweenInfo.new(0.12,Enum.EasingStyle.Back),{Size = UDim2.new(0.63,0,0.63,0)}):Play()
task.wait(0.05)
TweenService:Create(MapWindow["The Park"],TweenInfo.new(0.2,Enum.EasingStyle.Back),{Size = UDim2.new(0.65,0,0.65,0)}):Play()
end)()
SelectedButton = nil
task.wait()
SelectedButton = Button
print(SelectedButton)
for i, Levels in pairs(ReplicatedStorage.Episodes[SelectedButton.Name]:GetChildren())do
if Levels:IsA("Configuration") then
local DefaultLevel
local template = ReplicatedStorage.Episodes.EpisodeTemplate
local newTemplate = template:Clone()
for i, Values in pairs(Levels:GetChildren()) do
if Values:IsA("BoolValue") then
DefaultLevel = Values.Parent.LevelName.Value
end
end
print(DefaultLevel)
newTemplate.LevelName.Text = Levels.LevelName.Value
newTemplate.Name = Levels.LevelName.Value
newTemplate.Number.Text = Levels.Level.Value
newTemplate.LayoutOrder = Levels.LayoutOrder.Value
newTemplate.Parent = gui.LevelSelector.Episodes.EpisodeWindow
if newTemplate.Name == DefaultLevel then
StageChange:FireServer("Level", DefaultLevel)
newTemplate.UIStroke.Transparency = 0
newTemplate.Frame.BackgroundTransparency = 0.9
SelectedLevel = newTemplate
coroutine.wrap(function()
TweenService:Create(newTemplate,TweenInfo.new(0.3,Enum.EasingStyle.Back),{Size = UDim2.new(0,300,0,70)}):Play()
task.wait(0.05)
TweenService:Create(newTemplate,TweenInfo.new(0.12,Enum.EasingStyle.Back),{Size = UDim2.new(0,150,0,45)}):Play()
task.wait(0.05)
TweenService:Create(newTemplate,TweenInfo.new(0.2,Enum.EasingStyle.Back),{Size = UDim2.new(0,200,0,50)}):Play()
end)()
end
newTemplate.Activated:Connect(function()
if SelectedLevel == newTemplate then return end
if SelectedLevel then
SelectedLevel.UIStroke.Transparency = 1
SelectedLevel.Frame.BackgroundTransparency = 0.15
TweenService:Create(newTemplate,TweenInfo.new(0.18,Enum.EasingStyle.Back),{Size = UDim2.new(0.768,0,0.05,0)}):Play()
task.wait()
end
task.wait()
SelectedLevel = newTemplate
SelectedLevel.UIStroke.Transparency = 0
SelectedLevel.Frame.BackgroundTransparency = 0.9
StageChange:FireServer("Level", newTemplate.Name)
coroutine.wrap(function()
TweenService:Create(newTemplate,TweenInfo.new(0.3,Enum.EasingStyle.Back),{Size = UDim2.new(0,300,0,70)}):Play()
task.wait(0.05)
TweenService:Create(newTemplate,TweenInfo.new(0.12,Enum.EasingStyle.Back),{Size = UDim2.new(0,150,0,45)}):Play()
task.wait(0.05)
TweenService:Create(newTemplate,TweenInfo.new(0.2,Enum.EasingStyle.Back),{Size = UDim2.new(0,200,0,50)}):Play()
end)()
end)
end
end
end)
end
end