hello! im having a bug where when i clone a templates to a scrollingframe on the server, when the player resets it does not show the templates i cloned. I turned on “ResetIOnSpawn” to try and fix this it would but it didn’t seem to work. What is the reason for this issue?
– server script
local players = game:GetService("Players")
local replicatedStorage = game:GetService("ReplicatedStorage")
local mechanics = replicatedStorage:WaitForChild("mechanics")
local openNpcShopModule = require(mechanics:WaitForChild("Ui"):WaitForChild("openNpcShop"))
local unlockWeaponEvent = mechanics:WaitForChild("npcs"):WaitForChild("weaponDealer"):WaitForChild("unlockWeaponEvent")
local notifyOnServerEvent = mechanics:WaitForChild("notifications"):WaitForChild("NotifyOnServer")
local npcs = mechanics:WaitForChild("npcs")
local weaponDealer = npcs:WaitForChild("weaponDealer")
local weapons = weaponDealer:WaitForChild("weapons")
local weaponStatsModule = require(replicatedStorage:WaitForChild("client"):WaitForChild("weaponStats"))
players.PlayerAdded:Connect(function(player)
local playerStats = player:FindFirstChild("playerStats")
local otherStats = player:FindFirstChild("otherStats")
local function waitForChild(parent, childName, timeout)
local startTime = tick()
while not parent:FindFirstChild(childName) do
if timeout and (tick() - startTime) >= timeout then
warn(childName .. " not found within timeout")
return nil
end
task.wait(0.1)
end
return parent:FindFirstChild(childName)
end
playerStats = waitForChild(player, "playerStats", 10)
otherStats = waitForChild(player, "otherStats", 10)
if not playerStats or not otherStats then
warn("playerStats or otherStats not found within the given timeout.")
return
end
local playerCash = playerStats:FindFirstChild("cash")
local function buy(weapon, price)
local character = player.Character or player.CharacterAdded:Wait()
local backpack = player.Backpack
if backpack:FindFirstChild(weapon.Name) then
notifyOnServerEvent:FireClient(player, "you already have this", "negative")
return
end
if character:FindFirstChild(weapon.Name) then
notifyOnServerEvent:FireClient(player, "you already have this", "negative")
return
end
if playerCash.Value < price then
notifyOnServerEvent:FireClient(player, "your too broke💀", "negative")
return
end
local unlocked = weaponStatsModule:getWeaponAttribute(player, weapon.Name, "unlocked")
if playerCash.Value >= price and unlocked == true then
playerCash.Value -= price
local tool = weapon:Clone()
tool.Parent = backpack
notifyOnServerEvent:FireClient(player, "successfully bought " .. weapon.Name, "positive")
end
end
local unlockedItemsTable = weaponStatsModule:getUnlockedWeapons(player)
local lockedItemsTable = weaponStatsModule:getLockedWeapons(player)
local playerGui = player:WaitForChild("PlayerGui")
local scrollingFrame = playerGui:WaitForChild("npcGui"):WaitForChild("weaponDealerFrame"):WaitForChild("ScrollingFrame")
for _, weaponName in ipairs(unlockedItemsTable) do
if weapons:FindFirstChild(weaponName) then
local weapon = weapons:FindFirstChild(weaponName)
local template = replicatedStorage:WaitForChild("mechanics"):WaitForChild("npcs"):WaitForChild("weaponDealer"):WaitForChild("template"):Clone()
local lockedFrame = template:FindFirstChild("lockedFrame")
local info = template:FindFirstChild("info")
local image = template:FindFirstChild("imageFrame"):FindFirstChild("weaponImage")
local weaponTitle = info:FindFirstChild("weaponName")
local weaponDescription = info:FindFirstChild("weaponDescription")
local purchasebutton = info:FindFirstChild("buyButton")
print("Cloned unlocked template for weapon: " .. weaponName)
lockedFrame:Destroy()
local price = weaponStatsModule:getWeaponAttribute(player, weaponName, "price")
image.Image = weaponStatsModule:getWeaponAttribute(player, weaponName, "image")
weaponTitle.Text = "- " .. weaponName
weaponDescription.Text = weaponStatsModule:getWeaponAttribute(player, weaponName, "description")
purchasebutton.cashText.Text = "buy - $" .. tostring(price)
template.Name = weaponName
template.Parent = scrollingFrame
purchasebutton.MouseButton1Click:Connect(function()
buy(weapon, price)
end)
else
end
end
for _, weaponName in ipairs(lockedItemsTable) do
if weapons:FindFirstChild(weaponName) then
local weapon = weapons:FindFirstChild(weaponName)
local template = replicatedStorage:WaitForChild("mechanics"):WaitForChild("npcs"):WaitForChild("weaponDealer"):WaitForChild("template"):Clone()
local lockedFrame = template:FindFirstChild("lockedFrame")
local info = template:FindFirstChild("info")
local image = template:FindFirstChild("imageFrame"):FindFirstChild("weaponImage")
local weaponTitle = info:FindFirstChild("weaponName")
local weaponDescription = info:FindFirstChild("weaponDescription")
local purchasebutton = info:FindFirstChild("buyButton")
local unlockButton = lockedFrame:FindFirstChild("unlockButton")
local unlockCashText = lockedFrame:FindFirstChild("cashAmountText")
local unlockAmount = weaponStatsModule:getWeaponAttribute(player, weaponName, "unlockAmount")
unlockCashText.Text = "$" .. tostring(unlockAmount)
print("Cloned locked template for weapon: " .. weaponName)
lockedFrame.Visible = true
local price = weaponStatsModule:getWeaponAttribute(player, weaponName, "price")
image.Image = weaponStatsModule:getWeaponAttribute(player, weaponName, "image")
weaponTitle.Text = "- " .. weaponName
weaponDescription.Text = weaponStatsModule:getWeaponAttribute(player, weaponName, "description")
purchasebutton.cashText.Text = "buy - $" .. tostring(price)
template.Name = weaponName
template.Parent = scrollingFrame
unlockWeaponEvent.OnInvoke = function(player, weaponName)
local success = false
if playerCash.Value >= unlockAmount then
playerCash.Value -= unlockAmount
local template = scrollingFrame:FindFirstChild(weaponName)
local lockedFrame = template:FindFirstChild("lockedFrame")
lockedFrame:Destroy()
success = true
print("good")
elseif playerCash.Value < unlockAmount then
notifyOnServerEvent:FireClient(player, "your too broke💀", "negative")
warn("bad")
end
return success
end
unlockButton.MouseButton1Click:Connect(function()
weaponStatsModule:unlockWeapon(player, weaponName)
end)
purchasebutton.MouseButton1Click:Connect(function()
local NewunlockedItemsTable = weaponStatsModule:getUnlockedWeapons(player)
if table.find(NewunlockedItemsTable, weaponName) then
print("found")
buy(weapon, unlockAmount)
end
end)
else
end
end
end)