-- Core UI localscript
local availableTools = game.ReplicatedStorage:WaitForChild("GetTools"):InvokeServer()
local mainFrame = script.Parent:WaitForChild("MainFrame")
local safeArea = mainFrame:WaitForChild("SafeArea")
local itemInformation = safeArea:WaitForChild("ItemInformation")
local infoFrame = itemInformation.InfoFrame
local selectedItem = itemInformation.SelectedItem
local equippedItem = itemInformation.EquippedItem
local numberOfItems = #availableTools
local itemFrame = safeArea.ItemFrame
local shopButton = script.Parent:WaitForChild("ShopButton")
local buyButton = infoFrame.BuyButton
local equippedItemViewport = script.Parent:WaitForChild("EquippedItemViewport")
local itemViewport = itemInformation.ItemViewport
shopButton.MouseButton1Down:Connect(function()
mainFrame.Visible = not mainFrame.Visible
end)
local PADDING_X = 0.02
local DROPDOWN_Y = 0.2
local DROPDOWN_X = 0.25
local item1 = itemFrame:WaitForChild("Item1")
local box
local numRows = 1
for i = 1,numberOfItems,1 do
if i == 1 then
box = item1
else
box = item1:Clone()
box.Name = "item"..i
box.Parent = itemFrame
if (i-1) / (4*numRows) == 1 then
-- New Row
numRows = numRows + 1
box.Position = UDim2.new (PADDING_X,0,box.Position.Y.Scale,0) + UDim2.new(0,0,DROPDOWN_Y*(numRows - 1))
else
-- Add TO THE X ONLY
box.Position = itemFrame["item"..(i-1)]
end
end
end
COMMUNITY QUESTION
How to make that Shop gui open/close button at the same button?
2 answers
You could add an open variable to use the same button
-- Core UI localscript
local open = false
local availableTools = game.ReplicatedStorage:WaitForChild("GetTools"):InvokeServer()
local mainFrame = script.Parent:WaitForChild("MainFrame")
local safeArea = mainFrame:WaitForChild("SafeArea")
local itemInformation = safeArea:WaitForChild("ItemInformation")
local infoFrame = itemInformation.InfoFrame
local selectedItem = itemInformation.SelectedItem
local equippedItem = itemInformation.EquippedItem
local numberOfItems = #availableTools
local itemFrame = safeArea.ItemFrame
local shopButton = script.Parent:WaitForChild("ShopButton")
local buyButton = infoFrame.BuyButton
local equippedItemViewport = script.Parent:WaitForChild("EquippedItemViewport")
local itemViewport = itemInformation.ItemViewport
shopButton.MouseButton1Down:Connect(function()
if open == false then
mainFrame.Visible = true
open = true
else
mainFrame.Visible = false
open = false
end
mainFrame.Visible = not mainFrame.Visible
end)
local PADDING_X = 0.02
local DROPDOWN_Y = 0.2
local DROPDOWN_X = 0.25
local item1 = itemFrame:WaitForChild("Item1")
local box
local numRows = 1
for i = 1,numberOfItems,1 do
if i == 1 then
box = item1
else
box = item1:Clone()
box.Name = "item"..i
box.Parent = itemFrame
if (i-1) / (4*numRows) == 1 then
-- New Row
numRows = numRows + 1
box.Position = UDim2.new (PADDING_X,0,box.Position.Y.Scale,0) + UDim2.new(0,0,DROPDOWN_Y*(numRows - 1))
else
-- Add TO THE X ONLY
box.Position = itemFrame["item"..(i-1)]
end
end
end
2 comments
0
Also I can tell this is from the Alvinblox tutorial series on making a sword fighting game, hope it helps you get better at scripting dude!
0
wdym? i just copied and pasted his code and added my open stuff
There is a simple way of doing this.
for the on button click you can type this code:
shopButton.MouseButton1Down:Connect(function()
mainFrame.Visible = not mainFrame.Visible;
end);
when putting not there, if visible is true then not means false, if visible is false then not means true. not can mean opposite or in stuff like if statements you can do "if not 1 > 2 then" as in if 1 is not greater than 2. I hope this explanation helps you learn and the code can be kept simple.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Nice job, Alvin_Blox's shop gui! xD