Hello! I’m currently presented with an issue where a UI “clones” in place but doesn’t show up anywhere. I’ve ran multiple prints, of which none of them are nil, but the only difference is that on the first time the event causing the UI to clone is fired, it appears, while on the second and consecutive times it does not show up. Any help or insight as to why this may occur is greatly appreciated!
The LocalScript
causing ShopOpen
to toggle
buttonFrame.ShopButton.MouseButton1Click:Connect(function()
print(currentPlayerInput)
if toggled == true then
toggled = false
if newClone ~= nil then
newClone:Destroy()
end
else
toggled = true
if currentPlayerInput == "Touch" then
newClone = game:GetService("ReplicatedStorage").PlayerDisplay.MobileDisplays.MobileShopOpen:Clone()
newClone.Parent = playerDisplay
else
newClone = game:GetService("ReplicatedStorage").PlayerDisplay.ShopOpen:Clone()
newClone.Parent = playerDisplay
end
end
end)
LocalScript
local player = game:GetService("Players").LocalPlayer
local playerDisplay = player.PlayerGui:WaitForChild("PlayerDisplay")
local shopOpen = playerDisplay:WaitForChild("ShopOpen")
local itemsDisplay = shopOpen.ItemDisplay
local itemsFrame = shopOpen.ItemsFrame
local gameItem = shopOpen.LocalScript.GameItem
local paidItem = shopOpen.LocalScript.PaidItem
local exchangeItem = shopOpen.LocalScript.ExchangeItem
local ItemDisplayModule = require(game:GetService("ReplicatedStorage").ReplicatedMain.ItemsDisplayModule)
--RemoteFunctions
local passProductsFunction = game:GetService("ReplicatedStorage").RemoteFunctions.PassProducts
local purchaseFunction = game:GetService("ReplicatedStorage").RemoteFunctions.Purchase
--Buttons
local ingameShop = shopOpen.IngameShop
local paidShop = shopOpen.PaidProducts
local exchange = shopOpen.Exchange
--Properties
shopOpen.CoinsDisplay.TextLabel.Text = player:WaitForChild("PlayerData").Coins.Value
shopOpen.DiamondsDisplay.TextLabel.Text = player:WaitForChild("PlayerData").Diamonds.Value
--Events
player:WaitForChild("PlayerData").Coins.Changed:Connect(function(changedValue)
shopOpen.CoinsDisplay.TextLabel.Text = changedValue
end)
player:WaitForChild("PlayerData").Diamonds.Changed:Connect(function(changedValue)
shopOpen.DiamondsDisplay.TextLabel.Text = changedValue
end)
local itemTable
ingameShop.MouseButton1Click:Connect(function()
itemTable = passProductsFunction:InvokeServer("IngameShop")
ItemDisplayModule.onButtonInput(gameItem, itemTable)
end)
The Script
returning the table and its keys
--Functions
local passProductsFunction = game:GetService("ReplicatedStorage").RemoteFunctions.PassProducts
local purchaseFunction = game:GetService("ReplicatedStorage").RemoteFunctions.Purchase
--Products
local gameProducts = {
["Skateboard"] = {Image = "rbxassetid://78488228", TypeImage = "", CoinsCost = 500, DiamondsCost = 50, Description = "Rule the skate rink with this ROBLOX classic!"},
["Sword"] = {Image = "rbxassetid://9254600155", CoinsCost = 350, DiamondsCost = 35, Description = "Crush your enemies with this sword!"},
["Plushie"] = {Image = "rbxassetid://1922876607", CoinsCost = 100, DiamondsCost = 10, Description = "A soft plushie to cushion your emotions inside of."},
["Bloxy Cola"] = {Image = "rbxassetid://25119035", CoinsCost = 50, DiamondsCost = 5, Description = "Dangerously delicious contents."}
}
local paidProducts = {
["3x MORE!"] = {Image = "rbxassetid://862638100", ID = 1302031, RobuxCost = 100, Description = "Get 3x MORE!"},
["6x MORE!"] = {Image = "rbxassetid://862638100", ID = 4602402, RobuxCost = 100, Description = "Get 6x MORE!"}
}
local exchangeProducts = {
["50x!"] = {Image = "rbxassetid://862638100", CoinsCost = 500, Description = "50 diamonds for 500 coins!"},
["1000x!"] = {Image = "rbxassetid://862638100", CoinsCost = 10000, Description = "1000 diamonds for 10000 coins!"}
}
--RemoteFunctions
passProductsFunction.OnServerInvoke = function(player, guiObject)
local itemTable
if guiObject == "IngameShop" then
itemTable = gameProducts
elseif guiObject == "PaidProducts" then
itemTable = paidProducts
elseif guiObject == "Exchange" then
itemTable = exchangeProducts
end
return itemTable
end
The ModuleScript
handles the cloning of the UIObject
, depending on the number of keys stored inside of the table.
module.onButtonInput = function(itemFrame, itemTable)
--Destroy everything first
for i,v in ipairs(itemsFrame:GetChildren()) do
if v:IsA("TextButton") then
v:Destroy()
end
end
--Show items
local success, errMsg
for k,v in pairs(itemTable) do
local newItem = itemFrame:Clone()
newItem.Parent = itemsFrame
newItem.Text = k
print(newItem, newItem.Parent)
success, errMsg = pcall(function()
newItem.Image.Image = v.Image
end)
if not success then
warn("Image not found".."\t"..errMsg)
end
newItem.MouseButton1Click:Connect(function()
if v.CoinsCost then
itemsDisplay.Price.Text = "$"..tostring(v.CoinsCost)
elseif v.RobuxCost then
itemsDisplay.Price.Text = "R$"..tostring(v.RobuxCost)
end
itemsDisplay.Title.Text = k
itemsDisplay.Description.Text = v.Description
success, errMsg = pcall(function()
itemsDisplay.ImageLabel.Image = v.Image
end)
if not success then
warn("Image not found".."\t"..errMsg)
end
end)
end
end
1st Print
2nd Print, after ShopOpen
is toggled off and back on