So basically, I am making a series of scripts that will help with making a dynamic shop UI where if I just add a table element to a table in a module script, then it will show up on the shop UI as a button group. This code works on the first spawn, but with subsequent spawns, the item button group will not render even though the script can send a RemoteEvent and the LocalScript handling the UI can receive and interpret the data given to it. There are no errors being shown.
The main script:
local itemModule = require(game.ReplicatedStorage.items) --refers to modulescript
local items = itemModule.items
local disposables = itemModule.disposables
local players = game:GetService("Players")
local repStorage = game:GetService("ReplicatedStorage")
local DataStoreService = game:GetService("DataStoreService")
local dataStore = DataStoreService:GetDataStore("saveData")
local serverStore = game:GetService("ServerStorage")
players.PlayerAdded:Connect(function(player)
local sword = false
player.CharacterAdded:Connect(function(character)
local player = players:GetPlayerFromCharacter(character)
repStorage.storeLoad:FireClient(player, items, "tab0", "shopItem") --RemoteEvent here
repStorage.storeLoad:FireClient(player, disposables, "tab1", "disposibleItem") --RemoteEvent here
end)
local data = Instance.new("Folder")
data.Name = player.Name
data.Parent = serverStore
local items1 = repStorage.playerItems:Clone() --this is referring to a modulescript
items1.Parent = data
local disposables1 = repStorage.playerDisposables:Clone()
disposables1.Parent = data
local cash = Instance.new("IntValue")
cash.Name = "cash"
cash.Parent = data
local playerItems = require(items1)
local playerDisposables = require(disposables1)
local success, errorMessage = pcall(function()
if dataStore:GetAsync(player.UserId.."item") ~= nil then
playerItems = dataStore:GetAsync(player.UserId.."item")
end
playerDisposables = dataStore:GetAsync(player.UserId.."disposables")
cash.Value = dataStore:GetAsync(player.UserId.."cash")
end)
if success then
print("player data successfully loaded")
else
print("player data load failed")
warn(errorMessage)
end
for i,v in pairs(playerItems) do
if v[1] == "regularSword" then
sword = true
end
end
if sword == false then
table.insert(playerItems, {"regularSword", "Common", "single"})
end
end)
The GUI script:
local players = game:GetService("Players")
local repStorage = game:GetService("ReplicatedStorage")
local repFirst = game:GetService("ReplicatedFirst")
local storeLoad = repStorage:WaitForChild("storeLoad") --RemoteEvent
local player = players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local storeGui = playerGui:WaitForChild("shopGui")
local storeFrame = storeGui:WaitForChild("store")
storeLoad.OnClientEvent:Connect(function(items, location, type)
for i,v in pairs(items) do
local item = repFirst:WaitForChild(type):Clone()
item.Parent = storeFrame:WaitForChild(location)
item.ZIndex = 5
item.name.Text = v[1]
item.amount.Value = v[2]
item.maxPurchase.Value = v[3]
if type == "disposibleItem" then
item.productId.Value = v[4]
end
end
end)
