Hi, I’m kind of new to the Lua programming language and need help to make my code more efficient and better looking. How can I make this better??
Code:
CheckSword = script.Parent.Parent.ImagePreview.Image -- Find Out what sword it is by the preview image
SwordPrice = script.Parent.Parent.Price.Text -- Find Out Sword Price By the Price text
CashLocation = script.Parent.Parent.Parent.Parent.Parent.Parent.leaderstats.Cash.Value -- Location of the cash in leaderstats
SwordsFolder = script.Parent.Parent.Parent.Parent.Parent.Parent.Swords -- Folder With all the values of owned swords
function BuyItem() --- Script By Silverblade2005
print("Button Clicked!")
if CheckSword == "Sword1" then
CashLocation = CashLocation - tonumber(SwordPrice) --- Script By Silverblade2005
SwordsFolder.Sword1.Value = SwordsFolder.Sword1.Value + 1
print("Item Purchased!")
elseif CheckSword == "Sword2" then
CashLocation = CashLocation - tonumber(SwordPrice) --- Script By Silverblade2005
SwordsFolder.Sword2.Value = SwordsFolder.Sword2.Value + 1
print("Item Purchased!")
elseif CheckSword == "Sword3" then
CashLocation = CashLocation - tonumber(SwordPrice) --- Script By Silverblade2005
SwordsFolder.Sword3.Value = SwordsFolder.Sword3.Value + 1
print("Item Purchased!")
elseif CheckSword == "Sword4" then
CashLocation = CashLocation - tonumber(SwordPrice) --- Script By Silverblade2005
SwordsFolder.Sword4.Value = SwordsFolder.Sword4.Value + 1
print("Item Purchased!")
elseif CheckSword == "Sword5" then
CashLocation = CashLocation - tonumber(SwordPrice) --- Script By Silverblade2005
SwordsFolder.Sword5.Value = SwordsFolder.Sword5.Value + 1
print("Item Purchased")
end
end
script.Parent.MouseButton1Down:Connect(BuyItem)
And thank you for your help!