I'm making a character creator, but I feel like it has too many else ifs. I was wondering if there was anything that I could use to clean this up and make it easier to read/edit:
wait(1)
local Player = game.Players.LocalPlayer
local Shirt = 0
local Pants = 0
----------------------------------------------------------------------------------------------------------------------------
script.Parent.Frame.ShirtButton.MouseButton1Click:Connect(function()
if Shirt == 0 then
Shirt = 1
game.ReplicatedStorage.CharItems.Shirt1:Clone().Parent = workspace.You
elseif Shirt == 1 then
Shirt = 2
workspace.You.Shirt1:Destroy()
game.ReplicatedStorage.CharItems.Shirt2:Clone().Parent = workspace.You
elseif Shirt == 2 then
Shirt = 3
workspace.You.Shirt2:Destroy()
game.ReplicatedStorage.CharItems.Shirt3:Clone().Parent = workspace.You
elseif Shirt == 3 then
Shirt = 4
workspace.You.Shirt3:Destroy()
game.ReplicatedStorage.CharItems.Shirt4:Clone().Parent = workspace.You
elseif Shirt == 4 then
workspace.You.Shirt4:Destroy()
Shirt = 1
game.ReplicatedStorage.CharItems.Shirt1:Clone().Parent = workspace.You
end
end)
------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
script.Parent.Frame.PantsButton.MouseButton1Click:Connect(function()
if Pants == 0 then
Pants = 1
game.ReplicatedStorage.CharItems.Pants1:Clone().Parent = workspace.You
elseif Pants == 1 then
Pants = 2
workspace.You.Pants1:Destroy()
game.ReplicatedStorage.CharItems.Pants2:Clone().Parent = workspace.You
elseif Pants == 2 then
Pants = 3
workspace.You.Pants2:Destroy()
game.ReplicatedStorage.CharItems.Pants3:Clone().Parent = workspace.You
elseif Pants == 3 then
Pants = 4
workspace.You.Pants3:Destroy()
game.ReplicatedStorage.CharItems.Pants4:Clone().Parent = workspace.You
elseif Pants == 4 then
workspace.You.Pants4:Destroy()
Pants = 1
game.ReplicatedStorage.CharItems.Pants1:Clone().Parent = workspace.You
end
end)
------------------------------------------------------------------------------------------------------------
Thanks for the help

3 comments
you simply cant
He can do it in a simple way. It's not impossible
oh i was making fun of the notorious "how can i shorten this code" post. i cant seem to find the link though.