Hello silly gooses! This local script is the bread and pudding part of a working ShopGUI and I just wanted to know if anything like simplicity in the coding could be done as I’m still new to coding in Lua, about 2 weeks in. I wanted to see if there was a possibility in making the code more efficient and looking cleaner and just making it more easier to read so that future edits wont be a hassle.
local shop = script.Parent
local home = shop:WaitForChild("Home")
local inv = shop:WaitForChild("Inventory")
local gp = shop:WaitForChild("Gamepasses")
local sh = shop:WaitForChild("Shop")
local zi = shop:WaitForChild("ZombieInfo")
---------------------------------------
local ts = game:GetService("TweenService")
local popupslidebar = shop.Parent.Parent.Parent:WaitForChild("popupframe")
-- In position is {0, 0},{0, 0}
-- Out position is {0, 0},{-0.102, 0}
local dropdownbar = shop.Parent.Parent.Parent:WaitForChild("DropFrameInfo")
-- In position is {0, 0},{0.411, 0}
-- Out position is {0, 0},{0.963, 0}
local loadicon = shop.Parent.Parent.Parent.Parent:WaitForChild("Loading Boi").ImageLabel
local tweeninfoforload = TweenInfo.new(0.5,Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
local properties = {
Rotation = 360,
ImageTransparency = 1
}
local loading = ts:Create(loadicon, tweeninfoforload, properties)
local popupslidebarTxt = popupslidebar:WaitForChild("Decal"):WaitForChild("TextLabel") -- Change on button press, like which page was opened.
local plr = game:GetService("Players").LocalPlayer
local plrID = plr.UserId
local thumType = Enum.ThumbnailType.HeadShot
local thumSize = Enum.ThumbnailSize.Size420x420
local content = game.Players:GetUserThumbnailAsync(plrID, thumType, thumSize)
local typesound = shop:WaitForChild("Typesound")
local backsound = shop:WaitForChild("back")
-----------BUTTONS-----------------------------------------
-----HOME
local opt1 = home:WaitForChild("Options")
local invbtn = opt1:WaitForChild("Inventory"):WaitForChild("Button")
local shbtn = opt1:WaitForChild("Shop"):WaitForChild("Button")
local gpbtn = opt1:WaitForChild("Gamepasses"):WaitForChild("Button")
local zibtn = opt1:WaitForChild("ZombieInfo"):WaitForChild("Button")
-----INVENTORY
local backbtninv = inv:WaitForChild("backbtn"):WaitForChild("Button")
-----GAMEPASSES
local backbtngp = gp:WaitForChild("backbtn"):WaitForChild("Button")
-----SHOP
local shOptions = sh:WaitForChild("Options")
local shGuns = sh:WaitForChild("Guns")
local shGunFrames = sh:WaitForChild("GunFrames")
local ARf = shGunFrames:WaitForChild("AssaultF")
local Pf = shGunFrames:WaitForChild("PistolF")
local SGf = shGunFrames:WaitForChild("ShotgunF")
local SMGf = shGunFrames:WaitForChild("SmgF")
local SNf = shGunFrames:WaitForChild("SniperF")
-- local shThrow = sh:WaitForChild("Throwables")
-- local shMelee = sh:WaitForChild("Melees")
-- local shPets = sh:WaitForChild("Pets")
local WepSlotInfo = dropdownbar:WaitForChild("Decal"):WaitForChild("ImageLabel"):WaitForChild("Weapons")
local WepVPF = WepSlotInfo:WaitForChild("ViewportFrame")
local WepName = WepSlotInfo:WaitForChild("WeaponName").TextLabel
local WepPOS = WepSlotInfo:WaitForChild("PoS").TextLabel
local WepDMG = WepSlotInfo:WaitForChild("Dmg").TextLabel
local WepLVL = WepSlotInfo:WaitForChild("LvlReq").TextLabel
local WepDesc = WepSlotInfo:WaitForChild("Description").TextLabel
local WepQuote = WepSlotInfo:WaitForChild("Quote").TextLabel
local WepPurchase = WepSlotInfo:WaitForChild("Purchase").TextLabel
local PurchaseBtn = WepPurchase.Parent:WaitForChild("Button")
local PFBtn = PurchaseBtn.Parent
local dropActive = false
-----------
local backbtnsh = shOptions:WaitForChild("backbtn"):WaitForChild("Button")
local backbtnguns = shGuns:WaitForChild("backbtn"):WaitForChild("Button")
local backbtnAR = ARf:WaitForChild("backbtn"):WaitForChild("Button")
local backbtnP = Pf:WaitForChild("backbtn"):WaitForChild("Button")
local backbtnSG = SGf:WaitForChild("backbtn"):WaitForChild("Button")
local backbtnSMG = SMGf:WaitForChild("backbtn"):WaitForChild("Button")
local backbtnSN = SNf:WaitForChild("backbtn"):WaitForChild("Button")
local gunsbtn = shOptions:WaitForChild("Guns"):WaitForChild("Button")
local meleebtn = shOptions:WaitForChild("Melees"):WaitForChild("Button")
local throwbtn = shOptions:WaitForChild("Throwables"):WaitForChild("Button")
local petbtn = shOptions:WaitForChild("Pets"):WaitForChild("Button")
local arBtn = shGuns:WaitForChild("Assault Rifles"):WaitForChild("Button")
local pBtn = shGuns:WaitForChild("Pistols"):WaitForChild("Button")
local sgBtn = shGuns:WaitForChild("Shotguns"):WaitForChild("Button")
local smgBtn = shGuns:WaitForChild("Smgs"):WaitForChild("Button")
local snBtn = shGuns:WaitForChild("Snipers"):WaitForChild("Button")
----------------------------------------------------------------
local magpulBtn = ARf:WaitForChild("Selections"):WaitForChild("Magpul"):WaitForChild("Button")
local m4a1Btn = ARf:WaitForChild("Selections"):WaitForChild("m4a1"):WaitForChild("Button")
local usgBtn = Pf:WaitForChild("Selections"):WaitForChild("USG"):WaitForChild("Button")
local g19Btn = Pf:WaitForChild("Selections"):WaitForChild("G19"):WaitForChild("Button")
local deserteagleBtn = Pf:WaitForChild("Selections"):WaitForChild("DesertE"):WaitForChild("Button")
local pumpBtn = SGf:WaitForChild("Selections"):WaitForChild("Pump"):WaitForChild("Button")
local mossBtn = SGf:WaitForChild("Selections"):WaitForChild("Mossberg"):WaitForChild("Button")
local uziBtn = SMGf:WaitForChild("Selections"):WaitForChild("UZI"):WaitForChild("Button")
local mp5Btn = SMGf:WaitForChild("Selections"):WaitForChild("MP5"):WaitForChild("Button")
local skorBtn = SMGf:WaitForChild("Selections"):WaitForChild("SKORPION"):WaitForChild("Button")
local barrettBtn = SNf:WaitForChild("Selections"):WaitForChild("BARRETT"):WaitForChild("Button")
local dvlBtn = SNf:WaitForChild("Selections"):WaitForChild("DVL"):WaitForChild("Button")
-----ZOMBIEINFO
local backbtnzi = zi:WaitForChild("backbtn"):WaitForChild("Button")
-----------TEXTLABELS & SUCH--------------------------------
local hoversound = sh.Parent:WaitForChild("Select")
local clicksound = sh.Parent:WaitForChild("Click")
local dropsound = sh.Parent:WaitForChild("drop")
local pagesound = sh.Parent:WaitForChild("page")
local leavepagesound = sh.Parent:WaitForChild("exitpage")
-----HOME
local username = home:WaitForChild("UsersName")
local userimage = home:WaitForChild("UsersImage")
-- local usercash = home:WaitForChild("UsersCash")
-----INVENTORY
-------------------------FUNCTIONS------------------------------------
local function hideNshow(p1,p2)
p1.Visible = false
p2.Visible = true
end
local function typewrite(object,txt)
for i = 1,#txt do
object.Text = string.upper(string.sub(txt,1,i))
typesound:Play()
wait(0.01)
end
end
local function popUporDownBar(txt,num,db)
if num == 0 then
-- 0 meaning out
popupslidebarTxt.Text = txt
if popupslidebar.Position == UDim2.new(0,0,-.102,0) then
else
pagesound:Play()
popupslidebar:TweenPosition(UDim2.new(0,0,-.102,0),"Out","Quint",0.5,true)
end
elseif num == 1 then
-- 1 meaning in
if popupslidebar.Position == UDim2.new(0,0,0,0) then
else
leavepagesound:Play()
popupslidebar:TweenPosition(UDim2.new(0,0,0,0),"Out","Quint",0.5,true)
end
end
if db == 1 then
-- 1 meaning in
dropActive = false
dropdownbar:TweenPosition(UDim2.new(0,0,0.41,0),"Out","Quint",0.5,true)
elseif db == 0 then
-- 0 meaning out
dropActive = true
WepPOS.Text = ""
WepQuote.Text = ""
WepDesc.Text = ""
WepLVL.Text = "LVL: "
WepDMG.Text = "DMG: "
WepName.Text = ""
WepPurchase.Text = "NOTHING SELECTED"
dropsound:Play()
dropdownbar:TweenPosition(UDim2.new(0,0,0.95,0),"Out","Quint",0.5,true)
else
print("invalid input as only num allowed, no string input for num selection")
end
end
local function loadIn()
loadicon.ImageTransparency = 0
loading:Play()
end
local function WepStats(name,pos,quote,desc,lvlrq,dmg,amount)
WepPOS.Text = pos
WepQuote.Text = '"'..quote..'"'
WepDesc.Text = desc
WepLVL.Text = "LVL: "..lvlrq
WepDMG.Text = "DMG: "..dmg
if amount == 0 then
WepPurchase.Text = "OWNED"
else
WepPurchase.Text = "PURCHASE? ($"..amount..")"
end
if WepName.Text == name then
else
typewrite(WepName, name)
end
end
local function pbOut(timee)
PFBtn:TweenPosition(
UDim2.new(0.030,0,0.813,0),
"Out",
"Quint",
timee,
true
)
end
local function pbIn(timee)
PFBtn:TweenPosition(
UDim2.new(0.031,0,0.823,0),
"Out",
"Quint",
timee,
true
)
end
--[[
other functions add later
]]
-------------------------MAIN CODE------------------------------------
userimage.Image = content
------Home Page
invbtn.MouseButton1Click:Connect(function()
wait(0.1)
hideNshow(home,inv)
popUporDownBar("INVENTORY", 0,1)
loadIn()
end)
shbtn.MouseButton1Click:Connect(function()
wait(0.1)
hideNshow(home,sh)
popUporDownBar("SHOP",0,1)
loadIn()
end)
gpbtn.MouseButton1Click:Connect(function()
wait(0.1)
hideNshow(home,gp)
popUporDownBar("GAMEPASSES",0,1)
loadIn()
end)
zibtn.MouseButton1Click:Connect(function()
wait(0.1)
hideNshow(home,zi)
popUporDownBar("ZOMBIE INFO", 0,0)
loadIn()
end)
------Inventory Page
backbtninv.MouseButton1Click:Connect(function()
loadicon.Rotation = 0
wait(0.1)
backsound:Play()
hideNshow(inv,home)
popUporDownBar("",1,1)
typewrite(username, plr.Name)
end)
------Gamepasses Page
backbtngp.MouseButton1Click:Connect(function()
loadicon.Rotation = 0
wait(0.1)
backsound:Play()
hideNshow(gp,home)
popUporDownBar("",1,1)
typewrite(username, plr.Name)
end)
------Shop Page
backbtnsh.MouseButton1Click:Connect(function()
loadicon.Rotation = 0
wait(0.1)
backsound:Play()
hideNshow(sh,home)
popUporDownBar("",1,1)
typewrite(username, plr.Name)
end)
backbtnguns.MouseButton1Click:Connect(function()
wait(0.1)
backsound:Play()
hideNshow(shGuns,shOptions)
end)
-----Options page
gunsbtn.MouseButton1Click:Connect(function()
wait(0.1)
hideNshow(shOptions, shGuns)
end)
-----Guns Page
arBtn.MouseButton1Click:Connect(function()
wait(0.1)
hideNshow(shGuns, ARf)
popUporDownBar("SHOP",0,0)
end)
pBtn.MouseButton1Click:Connect(function()
wait(0.1)
hideNshow(shGuns,Pf)
popUporDownBar("SHOP",0,0)
end)
sgBtn.MouseButton1Click:Connect(function()
wait(0.1)
hideNshow(shGuns, SGf)
popUporDownBar("SHOP",0,0)
end)
smgBtn.MouseButton1Click:Connect(function()
wait(0.1)
hideNshow(shGuns, SMGf)
popUporDownBar("SHOP",0,0)
end)
snBtn.MouseButton1Click:Connect(function()
wait(0.1)
hideNshow(shGuns, SNf)
popUporDownBar("SHOP",0,0)
end)
---Assault Rifle
backbtnAR.MouseButton1Click:Connect(function()
wait(0.1)
backsound:Play()
hideNshow(ARf,shGuns)
popUporDownBar("SHOP",0,1)
end)
m4a1Btn.MouseButton1Click:Connect(function()
wait(0.1)
WepStats("COLT M4A1 ","PRIMARY","We ain't making it out of this one.","A sturdy and middle ranged rifle, used commonly by survivors in this world. Long range shooting is adequate, but could be better","3","8-16","2,000")
end)
magpulBtn.MouseButton1Click:Connect(function()
wait(0.1)
WepStats("MAGPUL MASADA ","PRIMARY","The loved child.","A reliable rifle that more tuned to dealing more damage far range than the M4A1. Besides its somewhat higher damage and faster shooting rate, it's mostly the same", "7","10-20","5,000")
end)
---Pistol
backbtnP.MouseButton1Click:Connect(function()
wait(0.1)
backsound:Play()
hideNshow(Pf,shGuns)
popUporDownBar("SHOP",0,1)
end)
usgBtn.MouseButton1Click:Connect(function()
wait(0.1)
WepStats("USG ","SECONDARY","Ol' Reliable","The ol' reliable, can't go anywhere without this baby. You and this gun have gone through tough times and back, even if it's showing its age.", "0", "12-18","0")
end)
g19Btn.MouseButton1Click:Connect(function()
wait(0.1)
WepStats("G19 ","SECONDARY","Better run, better run...","Modernized Glock variant ready for duty! Has higher base damage along with max damage for your pleasure, along with a bigger mag!","2","15-23","1,250")
end)
deserteagleBtn.MouseButton1Click:Connect(function()
wait(0.1)
WepStats("DESERT EAGLE ","SECONDARY","AMERICAAAA","Holy bajeezus, look at that damage! For trading off recoil control, get to experience one of the most deadly guns in the game!","12","45-90","10,000")
end)
---Shotgun
backbtnSG.MouseButton1Click:Connect(function()
wait(0.1)
backsound:Play()
hideNshow(SGf,shGuns)
popUporDownBar("SHOP",0,1)
end)
pumpBtn.MouseButton1Click:Connect(function()
wait(0.1)
WepStats("PUMP ","PRIMARY","No shot...","Hoofa! This thing packs a punch, both in recoil and damage! Won't do much in a horde but can do much on a focused target!","8","70-100","6,000")
end)
mossBtn.MouseButton1Click:Connect(function()
wait(0.1)
WepStats("MOSSBERG ","PRIMARY","SPAS, is that you?", "A Semi-Automatic shotgun with high damage capabilities! Can deal great significance in a horde along with a high mag count!", "15", "50-100","15,000")
end)
---SMG
backbtnSMG.MouseButton1Click:Connect(function()
wait(0.1)
backsound:Play()
hideNshow(SMGf,shGuns)
popUporDownBar("SHOP",0,1)
end)
uziBtn.MouseButton1Click:Connect(function()
wait(0.1)
WepStats("UZI ","SECONDARY","BZZZZZZZZ!","A fast small gun with great close combat abilities, as you won't be able to do much from far. Fast fire rate and bullets await you!","2","6-10","2,500")
end)
mp5Btn.MouseButton1Click:Connect(function()
wait(0.1)
WepStats("MP5 ","SECONDARY","Silly Gun","Better stability than its counterpart, along with a higher damage range. Far range damage is improved compared to the UZI","6","8-13","5,500")
end)
skorBtn.MouseButton1Click:Connect(function()
wait(0.1)
WepStats("SKORPION ","SECONDARY","ChickenSandwich's favorite.","Handling and stability improve along with damage range with this weapon, you could consider this a assault rifle if it weren't for its bullet feed.","11","10-16","8,500")
end)
---Sniper
backbtnSN.MouseButton1Click:Connect(function()
wait(0.1)
backsound:Play()
hideNshow(SNf,shGuns)
popUporDownBar("SHOP",0,1)
end)
barrettBtn.MouseButton1Click:Connect(function()
wait(0.1)
WepStats("BARRET M98B ","PRIMARY","Run Forest, run!","Aiming and speed are sacrificed to behold such a weapon. Bullet penetration is possible with this weapon.","18","200-400","20,000")
end)
dvlBtn.MouseButton1Click:Connect(function()
wait(0.1)
WepStats("DVL-10 ","PRIMARY","NoScope!!!! XD","A stable and versatile sniper that anyone can use easily. Bullet penetration is possible with this weapon","21","100-200","30,000")
end)
------DROPDOWNMENU
PurchaseBtn.MouseEnter:Connect(function()
if dropActive == true then
hoversound:Play()
pbOut(1)
end
end)
PurchaseBtn.MouseLeave:Connect(function()
if dropActive == true then
pbIn(1)
end
end)
PurchaseBtn.MouseButton1Click:Connect(function()
if dropActive == true then
pbIn(0.3)
clicksound:Play()
wait(0.15)
pbOut(0.3)
end
end)
------ZombieInfo Page
backbtnzi.MouseButton1Click:Connect(function()
loadicon.Rotation = 0
wait(0.1)
backsound:Play()
hideNshow(zi,home)
popUporDownBar("",1,1)
typewrite(username, plr.Name)
end)
I do want to mention that some parts of this code may seem incomplete, and that’s because it is. Please let me know if any adjustments to the current code can be made, thanks!