Hi guys! I’m pretty new to coding and have achieved a sort of level selection gui, inspired by the Super Mario Bros. 3 World Map design and sprite movement. Even though the movement from level-to-level works, I wonder if my code for it can be optimized (like lessening lines of code if possible).
Here’s a a script where my sprite moves from level 1 to 4.
script.Parent.Level4.MouseButton1Click:Connect(function()
task.wait(.00012)
print("1to4 triggered")
script.Parent.Lvl1to2.Disabled = true -- Every script except level 1 and 4 are disabled
script.Parent.Lvl1to3.Disabled = true
script.Parent.Level2.Lvl2to1.Disabled = true
script.Parent.Level2.Lvl2to3.Disabled = true
script.Parent.Level2.Lvl2to4.Disabled = true
script.Parent.Level3.Lvl3to1.Disabled = true
script.Parent.Level3.Lvl3to2.Disabled = true
script.Parent.Level3.Lvl3to4.Disabled = true
script.Parent.Level4.Lvl4to1.Enabled = true -- All scripts from level 4 are enabled
script.Parent.Level4.Lvl4to2.Enabled = true
script.Parent.Level4.Lvl4to3.Enabled = true
script.Parent.Play1.Visible = false
script.Parent.Sprite:TweenPosition(UDim2.new(2.682,0,-.775,0),"InOut","Linear",.375,false)
task.wait(.395)
script.Parent.Sprite:TweenPosition(UDim2.new(2.682,0,-2.976,0),"InOut","Linear",.5,false)
task.wait(.52)
script.Parent.Sprite:TweenPosition(UDim2.new(8.033,0,-2.976,0),"InOut","Linear",.35,false)
task.wait(.37)
script.Parent.Sprite:TweenPosition(UDim2.new(8.033,0,-1.359,0),"InOut","Linear",.225,false)
task.wait(.245)
script.Parent.Sprite:TweenPosition(UDim2.new(10.279,0,-1.359,0),"InOut","Linear",.35,false)
task.wait(.35)
script.Parent.Play4.Visible = true
end)
I got a sample and video of the level select below if more examples are needed.
level select.rbxl (64.2 KB)