I Need help with a shop script. I used a version of the shop template from AlvinBlox as a base, but I’m having a few problems with the shop tools not being transferred over to my inventory. The items are being place in the proper folders but not showing up in the inventory GUI. I’m running a for loop to get all the items in the folder, but I’ve noticed that if the items are in the folder before playing the game they will show up as i need them to, but if I play the game and then buy the items, they are added to the folder but don’t show up in gui. I’ve been trying for days on something that may take someone ten minutes. but I can’t move forward until I get this fixed, any help will be appreciated.
(Weapons Folder Empty)
(Weapons Folder After Buying Items From Shop)
(Video)
robloxapp-20220409-1411458.wmv (1.3 MB)
(Shop Script)
local gui = game.Players.LocalPlayer.PlayerGui
-- Inserts a template for every item in the Tools folder
local folder = game.ReplicatedStorage:WaitForChild("ShopItems")
local frame = gui.LobbyScreenGUI.StoreFrame.ShopFrame.ShopButton:WaitForChild("StoreFrontFrame")
local template = frame:WaitForChild("ShopScrollingFrame"):WaitForChild("ShopSlot")
local slot = gui.LobbyScreenGUI.InteractFrame.InventoryButton.InventoryFrame:FindFirstChild("WeaponsScrollingFrame"):FindFirstChild("WeaponsSlot"):WaitForChild("Title")
local weaponFolder = game.ReplicatedStorage.Weapons
local vehicalsFolder = game.ReplicatedStorage.Vehicals
local emoteFolder = game.ReplicatedStorage.Emotes
local miscellaneousFolder = game.ReplicatedStorage.Miscellaneous
local clothingFolder = game.ReplicatedStorage.Clothing
for _, item in pairs(folder:GetChildren()) do
local newTemplate = template:Clone()
newTemplate.Price.Text = "$"..item:WaitForChild("Cost").Value
newTemplate.Visible = true
newTemplate.Image = item.TextureId
--newTemplate.Price.Text = item.Name
newTemplate.Parent = frame.ShopScrollingFrame
slot.Text = "Equip"
newTemplate.Price.MouseButton1Click:Connect(function()
if game.Players.LocalPlayer.leaderstats.Money.Value >= item:WaitForChild("Cost").Value then
game.Players.LocalPlayer.leaderstats.Money.Value = game.Players.LocalPlayer.leaderstats.Money.Value - item:WaitForChild("Cost").Value
newTemplate.Price.Text = "Purchased"
newTemplate.Price.BackgroundColor = BrickColor.new("Bright green")
item:WaitForChild("Cost").Value = 0
if item:WaitForChild("ItemType").Value == "Clothing" then
local newTool = item:Clone()
newTool.Parent = miscellaneousFolder
elseif item:WaitForChild("ItemType").Value == "Weapons" then
local newTool = item:Clone()
newTool.Parent = weaponFolder
elseif item:WaitForChild("ItemType").Value == "Vehicals" then
local newTool = item:Clone()
newTool.Parent = vehicalsFolder
elseif item:WaitForChild("ItemType").Value == "Emotes" then
local newTool = item:Clone()
newTool.Parent = emoteFolder
elseif item:WaitForChild("ItemType").Value == "Miscellaneous" then
local newTool = item:Clone()
newTool.Parent = miscellaneousFolder
end
local newTool = item:Clone()
newTool.Parent = game.Players.LocalPlayer.Backpack
game.Players.LocalPlayer.leaderstats.Purchases.Value = 1
script.Parent.Parent.Availble.Visible = true
wait(1)
script.Parent.Parent.Availble.Visible = false
else
newTemplate.Price.Text = "Purchase Failed"
newTemplate.Price.BackgroundColor = BrickColor.new("Really red")
wait(2)
newTemplate.Price.Text = "$"..item:WaitForChild("Cost").Value
newTemplate.Price.BackgroundColor = BrickColor.new("White")
newTemplate.Price.BackgroundTransparency = 0.5
end
end)
end
(Weapons Script)
local folder = game.ReplicatedStorage:WaitForChild("Weapons")
local frame = gui.LobbyScreenGUI.InteractFrame.InventoryButton:WaitForChild("InventoryFrame")
local template = frame:WaitForChild("WeaponsScrollingFrame"):WaitForChild("WeaponsSlot")
for _, item in pairs(folder:GetChildren()) do
local newTemplate = template:Clone()
newTemplate.Visible = true
newTemplate.Image = item.TextureId
newTemplate.Parent = frame.WeaponsScrollingFrame
newTemplate.Title.Visible = true
newTemplate.Title.Text = "Equip"
end