You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
Hello developers! I am currently working on a game with a level select that lets you select from a wide variety of levels. -
What is the issue? Include screenshots / videos if possible!
I want to keep the script short and simple, and not have to copy and paste every .MouseEnter or .MouseLeave or .MouseButton1Click function for each button. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’m not sure, but maybe having a table with all the Ids of every level. And loop through that?
local TeleportService = game:GetService("TeleportService")
local SFX = script:WaitForChild("SFX")
local Click_sound = script:WaitForChild("ClickSound")
local Place_ID1 = 11453544275 -- Tropical Coast
local Place_ID2 = 10665512129 -- Wave Square
local Place_ID3 = 10669943980 -- Adrenaline Highway
local Place_ID4 = 10677378022 -- Snow Cap
local Place_ID5 = 10684140458 -- Ruined Base
local Place_ID6 = 10696025368 -- Seaside Coast
local Place_ID7 = 10892018924 -- Seaside Coast (ACT 2)
local Place_ID8 = 10892025301 -- Checker Hill
local Place_ID9 = 10892037059 -- Find your Flame
local Place_ID10 = 15264722817 -- Find your Flame (ACT 2)
Trial.MouseButton1Click:Connect(function()
if Confirmation.Visible == true then -- Stops from overlapping.
Confirmation.Visible = false
end
SFX:Play()
BaseGame.Visible = false
NoobStory.Visible = false
TheFinalRise.Visible = false
Shade.Visible = false
Shade2.Visible = false
Shade3.Visible = false
Story_Select.Visible = false
Story_SelectShadow.Visible = false
Guide.Visible = false
GuideShadow.Visible = false
if TrialFrame.Visible == false then -- If LevelselectFrame is not visible.
TrialFrame.Visible = true -- Make it visible.
else -- Or else...
TrialFrame.Visible = false
BaseGame.Visible = true
NoobStory.Visible = true
TheFinalRise.Visible = true
Shade.Visible = true
Shade2.Visible = true
Shade3.Visible = true
Story_Select.Visible = true
Story_SelectShadow.Visible = true
Guide.Visible = false
GuideShadow.Visible = false
end
end)
Stage01.MouseEnter:Connect(function()
Click_sound:Play()
Stage01.BackgroundColor3 = Color3.fromRGB(86, 316, 355)
end)
Stage01.MouseLeave:Connect(function()
Stage01.BackgroundColor3 = Color3.fromRGB(66, 116, 255)
end)
Stage02.MouseEnter:Connect(function()
Click_sound:Play()
Stage02.BackgroundColor3 = Color3.fromRGB(86, 316, 355)
end)
Stage02.MouseLeave:Connect(function()
Stage02.BackgroundColor3 = Color3.fromRGB(66, 116, 255)
end)
Stage03.MouseEnter:Connect(function()
Click_sound:Play()
Stage03.BackgroundColor3 = Color3.fromRGB(86, 316, 355)
end)
Stage03.MouseLeave:Connect(function()
Stage03.BackgroundColor3 = Color3.fromRGB(66, 116, 255)
end)
Stage04.MouseEnter:Connect(function()
Click_sound:Play()
Stage04.BackgroundColor3 = Color3.fromRGB(86, 316, 355)
end)
Stage04.MouseLeave:Connect(function()
Stage04.BackgroundColor3 = Color3.fromRGB(66, 116, 255)
end)
Stage05.MouseEnter:Connect(function()
Click_sound:Play()
Stage05.BackgroundColor3 = Color3.fromRGB(86, 316, 355)
end)
Stage05.MouseLeave:Connect(function()
Stage05.BackgroundColor3 = Color3.fromRGB(66, 116, 255)
end)
Stage06.MouseEnter:Connect(function()
Click_sound:Play()
Stage06.BackgroundColor3 = Color3.fromRGB(86, 316, 355)
end)
Stage06.MouseLeave:Connect(function()
Stage06.BackgroundColor3 = Color3.fromRGB(66, 116, 255)
end)
Stage07.MouseEnter:Connect(function()
Click_sound:Play()
Stage07.BackgroundColor3 = Color3.fromRGB(86, 316, 355)
end)
Stage07.MouseLeave:Connect(function()
Stage07.BackgroundColor3 = Color3.fromRGB(66, 116, 255)
end)
Stage08.MouseEnter:Connect(function()
Click_sound:Play()
Stage08.BackgroundColor3 = Color3.fromRGB(86, 316, 355)
end)
Stage08.MouseLeave:Connect(function()
Stage08.BackgroundColor3 = Color3.fromRGB(66, 116, 255)
end)
Stage09.MouseEnter:Connect(function()
Click_sound:Play()
Stage09.BackgroundColor3 = Color3.fromRGB(86, 316, 355)
end)
Stage09.MouseLeave:Connect(function()
Stage09.BackgroundColor3 = Color3.fromRGB(66, 116, 255)
end)
Stage10.MouseEnter:Connect(function()
Click_sound:Play()
Stage10.BackgroundColor3 = Color3.fromRGB(86, 316, 355)
end)
Stage10.MouseLeave:Connect(function()
Stage10.BackgroundColor3 = Color3.fromRGB(66, 116, 255)
end)
Stage01.MouseButton1Click:Connect(function()
SFX:Play()
TeleportService:Teleport(Place_ID1, player) -- Teleports the player.
end)
Stage02.MouseButton1Click:Connect(function()
SFX:Play()
TeleportService:Teleport(Place_ID2, player) -- Teleports the player.
end)
Stage03.MouseButton1Click:Connect(function()
SFX:Play()
TeleportService:Teleport(Place_ID3, player) -- Teleports the player.
end)
Stage04.MouseButton1Click:Connect(function()
SFX:Play()
TeleportService:Teleport(Place_ID4, player) -- Teleports the player.
end)
Stage05.MouseButton1Click:Connect(function()
SFX:Play()
TeleportService:Teleport(Place_ID5, player) -- Teleports the player.
end)
Stage06.MouseButton1Click:Connect(function()
SFX:Play()
TeleportService:Teleport(Place_ID6, player) -- Teleports the player.
end)
Stage07.MouseButton1Click:Connect(function()
SFX:Play()
TeleportService:Teleport(Place_ID7, player) -- Teleports the player.
end)
Stage08.MouseButton1Click:Connect(function()
SFX:Play()
TeleportService:Teleport(Place_ID8, player) -- Teleports the player.
end)
Stage09.MouseButton1Click:Connect(function()
SFX:Play()
TeleportService:Teleport(Place_ID9, player) -- Teleports the player.
end)
Stage10.MouseButton1Click:Connect(function()
SFX:Play()
TeleportService:Teleport(Place_ID10, player) -- Teleports the player.
end)