Hard to see from a video, but when I click the arrows, it takes around 0.5 seconds for the side bar to pop up. This is because I have to fire a RemoteFunction to the server to check to see what items a player has, so that way it can show the list of items with accurate labels (prices for items that the player does not own yet)
function createItems(opened)
clearButtons()
for _, item in pairs(classes[selectedClass][opened]:GetChildren()) do
local itemButton = Instance.new('ImageButton')
itemButton.BackgroundTransparency = 1
itemButton.Name = item.Name
itemButton.Size = UDim2.new(0.875, 0, 0.125, 0)
itemButton.SizeConstraint = 'RelativeXX'
itemButton.ZIndex = 2
itemButton.Image = 'rbxassetid://295943235'
itemButton.ImageColor3 = Color3.fromRGB(150, 150, 150)
itemButton.ScaleType = 'Slice'
itemButton.SliceCenter = Rect.new(10, 10, 20, 20)
local name = Instance.new('TextLabel')
name.AnchorPoint = Vector2.new(0, 0.5)
name.BackgroundTransparency = 1
name.Name = 'Label'
name.Position = UDim2.new(0.05, 0, 0.5, 0)
name.Size = UDim2.new(0.55, 0, 0.6, 0)
name.ZIndex = 2
name.Font = 'GothamBold'
name.Text = item.Name
name.TextColor3 = Color3.fromRGB(255, 255, 255)
name.TextScaled = true
name.TextXAlignment = 'Left'
local hasItem, equipped = checkClassItem:InvokeServer(selectedClass, opened, item.Name)
if hasItem then
if equipped then
local equip = Instance.new('TextLabel')
equip.AnchorPoint = Vector2.new(1, 0.5)
equip.BackgroundTransparency = 1
equip.Name = 'Cost'
equip.Position = UDim2.new(1, 0, 0.5, 0)
equip.Size = UDim2.new(0.275, 0, 0.6, 0)
equip.ZIndex = 2
equip.Font = 'GothamBlack'
equip.Text = 'Equipped'
equip.TextColor3 = Color3.fromRGB(255, 255, 255)
equip.TextScaled = true
equip.TextXAlignment = 'Left'
end
else
createCost(itemButton, name)
end
name.Parent = itemButton
itemButton.Parent = scrolling
end
end
Problem lying here:
local hasItem, equipped = checkClassItem:InvokeServer(selectedClass, opened, item.Name)
This:
- checks to see if they own the item and
- if that item is the currently equipped item.
Another problem, is since it’s slow to respond, if I click both the weapon and armour buttons before the function has returned, then it crates buttons for both the sword and armour.
This is what’s called at the top of the createButtons to remove the previous buttons from the list.
function clearButtons()
for _, button in pairs(scrolling:GetChildren()) do
if button:IsA('ImageButton') then
button:Destroy()
end
end
end
How can I go about speeding this process up?