Why am i getting this error?

Hello!

I am getting this error in my code:

I cant click on it or interact with it. Here is my code:

ReplicatedStorage Module:

-- Server Module
local MerchantItems = {}

function MerchantItems.Initialize(player)
	local LeaderstatsFolder = player:WaitForChild("leaderstats", 10)
	local BoostsFolder = player:WaitForChild("Boosts", 10)

	MerchantItems.Items = {
		["Potion1"] = {Potion = BoostsFolder["Gem Potion"], Time = 30, Image = "rbxassetid://15434984615", Title = "Gem Potion", MaxPurchase = 1,  Purchased = 0, Price = 12, Currency = LeaderstatsFolder:WaitForChild("Taps")},
		["Potion2"] = {Potion = BoostsFolder["Super Lucky"], Time = 60, Image = "rbxassetid://15434984615", Title = "Super Luck Potion", MaxPurchase = 2,  Purchased = 0, Price = 24, Currency = LeaderstatsFolder:WaitForChild("Taps")},
		["Potion3"] = {Potion = BoostsFolder["Extra Lucky"], Time = 90, Image = "rbxassetid://15434984615", Title = "Luck Potion", MaxPurchase = 3,  Purchased = 0, Price = 36, Currency = LeaderstatsFolder:WaitForChild("Taps")},
	}
end

function MerchantItems.CreatePotionPurchaseFrame(player, name)
	local Template = game:GetService("ReplicatedStorage"):WaitForChild("Potion1"):Clone()
	local gui = player.PlayerGui:WaitForChild("Main"):WaitForChild("TravellingMerchant")

	Template.Name = MerchantItems.Items[name].Title
	Template.Icon.Image = MerchantItems.Items[name].Image
	Template.PotionName.Text = MerchantItems.Items[name].Title
	Template.Purchased.Text = MerchantItems.Items[name].Purchased.."/"..MerchantItems.Items[name].MaxPurchase
	Template.PriceLabel.Text = MerchantItems.Items[name].Price.." "..MerchantItems.Items[name].Currency.Name

	Template.Parent = gui:WaitForChild("Main"):WaitForChild("Container")

	Template.BuyButton.Button.MouseButton1Click:Connect(function()
		game.ReplicatedStorage:WaitForChild("Merchant").PotionPurchase:FireServer(player, name)
	end)
end

function MerchantItems.GetItems()
	return MerchantItems.Items
end

return MerchantItems

ServerScriptService Script

-- Server Script
local mod = require(game:GetService("ReplicatedStorage"):WaitForChild("Merchant"):WaitForChild("MerchantItems"))
local Remote = game:GetService("ReplicatedStorage"):FindFirstChild("Merchant").PotionPurchase

Remote.OnServerEvent:Connect(function(player, purchaseThis)
	local Items = mod.GetItems() -- Use the function to get the items
	local info = Items[purchaseThis]
	local statsValue = player:WaitForChild("Boosts"):FindFirstChild(info.Title)

	if not statsValue or not info then
		warn("No Boost or info")
		return
	end

	local price = info.Price
	local currency = info.Currency
	local max = info.MaxPurchase
	local Purchased = info.Purchased

	if currency.Value >= price then
		currency.Value -= price
		statsValue.Value += info.Time
	end
end)

StarterPlayerScripts local script

-- Client Script (in StarterPlayerScripts)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MerchantItemsModule = ReplicatedStorage:WaitForChild("Merchant"):WaitForChild("MerchantItems")

if MerchantItemsModule and MerchantItemsModule:IsA("ModuleScript") then
	local MerchantHandler = require(MerchantItemsModule)

	-- Assuming you have the LocalPlayer object available
	local player = game.Players.LocalPlayer

	MerchantHandler.Initialize(player)
	MerchantHandler.CreatePotionPurchaseFrame(player, "Potion1")
	MerchantHandler.CreatePotionPurchaseFrame(player, "Potion2")
	MerchantHandler.CreatePotionPurchaseFrame(player, "Potion3")
else
	warn("MerchantItems module not found in ReplicatedStorage or not a ModuleScript.")
end

Please help, Thanks!

8 Likes

That warning shows up if an Instance takes longer than 5 seconds to finish loading

4 Likes

Thanks! Lets hope we don’t go through the Animated Billboard fiasco again lol.

How can i fix this?

4 Likes

Actually since Potion1 is inside of ReplicatedStorage you shouldn’t be getting this warning unless you’re adding it later on. You’ll need to use ChildAdded to detect when the potion is added to ReplicatedStorage

3 Likes

The potion is a numbervalue inside of a boostfolder which is inside the player. like leaderstats

1 Like

How does ReplicatedStorage look like in the Explorer?

2 Likes

image

2 Likes

The Potion1 frame is inside of a folder named Merchant so you need to change the module like so:

-- Server Module
local MerchantItems = {}

function MerchantItems.Initialize(player)
	local LeaderstatsFolder = player:WaitForChild("leaderstats", 10)
	local BoostsFolder = player:WaitForChild("Boosts", 10)

	MerchantItems.Items = {
		["Potion1"] = {Potion = BoostsFolder["Gem Potion"], Time = 30, Image = "rbxassetid://15434984615", Title = "Gem Potion", MaxPurchase = 1,  Purchased = 0, Price = 12, Currency = LeaderstatsFolder:WaitForChild("Taps")},
		["Potion2"] = {Potion = BoostsFolder["Super Lucky"], Time = 60, Image = "rbxassetid://15434984615", Title = "Super Luck Potion", MaxPurchase = 2,  Purchased = 0, Price = 24, Currency = LeaderstatsFolder:WaitForChild("Taps")},
		["Potion3"] = {Potion = BoostsFolder["Extra Lucky"], Time = 90, Image = "rbxassetid://15434984615", Title = "Luck Potion", MaxPurchase = 3,  Purchased = 0, Price = 36, Currency = LeaderstatsFolder:WaitForChild("Taps")},
	}
end

function MerchantItems.CreatePotionPurchaseFrame(player, name)
	local Template = game:GetService("ReplicatedStorage"):WaitForChild("Merchant"):WaitForChild("Potion1"):Clone()
	local gui = player.PlayerGui:WaitForChild("Main"):WaitForChild("TravellingMerchant")

	Template.Name = MerchantItems.Items[name].Title
	Template.Icon.Image = MerchantItems.Items[name].Image
	Template.PotionName.Text = MerchantItems.Items[name].Title
	Template.Purchased.Text = MerchantItems.Items[name].Purchased.."/"..MerchantItems.Items[name].MaxPurchase
	Template.PriceLabel.Text = MerchantItems.Items[name].Price.." "..MerchantItems.Items[name].Currency.Name

	Template.Parent = gui:WaitForChild("Main"):WaitForChild("Container")

	Template.BuyButton.Button.MouseButton1Click:Connect(function()
		game.ReplicatedStorage:WaitForChild("Merchant").PotionPurchase:FireServer(player, name)
	end)
end

function MerchantItems.GetItems()
	return MerchantItems.Items
end

return MerchantItems
3 Likes

Oh, i was thinking “Potion1” Was a potion since its defined in MerchantItems.Items. Not the frame lol, ill test it now

2 Likes

Thanks! It worked, but now im getting this error in the sever script:
image

3 Likes

I recommend making a naming scheme in order to minimise this kind of confusion, for example naming the template PotionTemplateFrame or something like that

Sometimes modules can be picky with initializing tables, this should work to solve it:

-- Server Module
local MerchantItems = {}

MerchantItems.Items = {}

function MerchantItems.Initialize(player)
	local LeaderstatsFolder = player:WaitForChild("leaderstats", 10)
	local BoostsFolder = player:WaitForChild("Boosts", 10)

	MerchantItems.Items = {
		["Potion1"] = {Potion = BoostsFolder["Gem Potion"], Time = 30, Image = "rbxassetid://15434984615", Title = "Gem Potion", MaxPurchase = 1,  Purchased = 0, Price = 12, Currency = LeaderstatsFolder:WaitForChild("Taps")},
		["Potion2"] = {Potion = BoostsFolder["Super Lucky"], Time = 60, Image = "rbxassetid://15434984615", Title = "Super Luck Potion", MaxPurchase = 2,  Purchased = 0, Price = 24, Currency = LeaderstatsFolder:WaitForChild("Taps")},
		["Potion3"] = {Potion = BoostsFolder["Extra Lucky"], Time = 90, Image = "rbxassetid://15434984615", Title = "Luck Potion", MaxPurchase = 3,  Purchased = 0, Price = 36, Currency = LeaderstatsFolder:WaitForChild("Taps")},
	}
end

function MerchantItems.CreatePotionPurchaseFrame(player, name)
	local Template = game:GetService("ReplicatedStorage"):WaitForChild("Merchant"):WaitForChild("Potion1"):Clone()
	local gui = player.PlayerGui:WaitForChild("Main"):WaitForChild("TravellingMerchant")

	Template.Name = MerchantItems.Items[name].Title
	Template.Icon.Image = MerchantItems.Items[name].Image
	Template.PotionName.Text = MerchantItems.Items[name].Title
	Template.Purchased.Text = MerchantItems.Items[name].Purchased.."/"..MerchantItems.Items[name].MaxPurchase
	Template.PriceLabel.Text = MerchantItems.Items[name].Price.." "..MerchantItems.Items[name].Currency.Name

	Template.Parent = gui:WaitForChild("Main"):WaitForChild("Container")

	Template.BuyButton.Button.MouseButton1Click:Connect(function()
		game.ReplicatedStorage:WaitForChild("Merchant").PotionPurchase:FireServer(player, name)
	end)
end

function MerchantItems.GetItems()
	return MerchantItems.Items
end

return MerchantItems
3 Likes

Here we go…

image

2 Likes

I’m noticing that the Initialize function is never called in the server Script, only in the LocalScript so my new edit to the module won’t work. You’ll need to initialize the table for the server to use otherwise the Items table will always be an empty table on the server

3 Likes

How would i do that? i suck at coding lol

2 Likes

This should work:

-- Server Script
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local mod = require(ReplicatedStorage:WaitForChild("Merchant"):WaitForChild("MerchantItems"))
local Remote = ReplicatedStorage:FindFirstChild("Merchant").PotionPurchase

Players.PlayerAdded:Connect(mod.Initialize)

Remote.OnServerEvent:Connect(function(player, purchaseThis)
	local Items = mod.GetItems() -- Use the function to get the items
	local info = Items[purchaseThis]
	local statsValue = player:WaitForChild("Boosts"):FindFirstChild(info.Title)

	if not statsValue or not info then
		warn("No Boost or info")
		return
	end

	local price = info.Price
	local currency = info.Currency
	local max = info.MaxPurchase
	local Purchased = info.Purchased

	if currency.Value >= price then
		currency.Value -= price
		statsValue.Value += info.Time
	end
end)
3 Likes

Still get the same error on line 13 :confused:

3 Likes

You might need to make a separate Items table for each player like so:
Module:

-- Server Module
local MerchantItems = {}

MerchantItems.Items = {}

function MerchantItems.Initialize(player)
	local LeaderstatsFolder = player:WaitForChild("leaderstats", 10)
	local BoostsFolder = player:WaitForChild("Boosts", 10)

	MerchantItems.Items[player.UserId] = {
		["Potion1"] = {Potion = BoostsFolder["Gem Potion"], Time = 30, Image = "rbxassetid://15434984615", Title = "Gem Potion", MaxPurchase = 1,  Purchased = 0, Price = 12, Currency = LeaderstatsFolder:WaitForChild("Taps")},
		["Potion2"] = {Potion = BoostsFolder["Super Lucky"], Time = 60, Image = "rbxassetid://15434984615", Title = "Super Luck Potion", MaxPurchase = 2,  Purchased = 0, Price = 24, Currency = LeaderstatsFolder:WaitForChild("Taps")},
		["Potion3"] = {Potion = BoostsFolder["Extra Lucky"], Time = 90, Image = "rbxassetid://15434984615", Title = "Luck Potion", MaxPurchase = 3,  Purchased = 0, Price = 36, Currency = LeaderstatsFolder:WaitForChild("Taps")},
	}
end

function MerchantItems.CreatePotionPurchaseFrame(player, name)
	local Template = game:GetService("ReplicatedStorage"):WaitForChild("Merchant"):WaitForChild("Potion1"):Clone()
	local gui = player.PlayerGui:WaitForChild("Main"):WaitForChild("TravellingMerchant")

	Template.Name = MerchantItems.Items[player.UserId][name].Title
	Template.Icon.Image = MerchantItems.Items[player.UserId][name].Image
	Template.PotionName.Text = MerchantItems.Items[player.UserId][name].Title
	Template.Purchased.Text = MerchantItems.Items[player.UserId][name].Purchased.."/"..MerchantItems.Items[player.UserId][name].MaxPurchase
	Template.PriceLabel.Text = MerchantItems.Items[player.UserId][name].Price.." "..MerchantItems.Items[player.UserId][name].Currency.Name

	Template.Parent = gui:WaitForChild("Main"):WaitForChild("Container")

	Template.BuyButton.Button.MouseButton1Click:Connect(function()
		game.ReplicatedStorage:WaitForChild("Merchant").PotionPurchase:FireServer(player, name)
	end)
end

function MerchantItems.GetItems(player)
	return MerchantItems.Items[player.UserId]
end

return MerchantItems

Server:

-- Server Script
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local mod = require(ReplicatedStorage:WaitForChild("Merchant"):WaitForChild("MerchantItems"))
local Remote = ReplicatedStorage:FindFirstChild("Merchant").PotionPurchase

Players.PlayerAdded:Connect(mod.Initialize)

Remote.OnServerEvent:Connect(function(player, purchaseThis)
	local Items = mod.GetItems(player) -- Use the function to get the items
	local info = Items[purchaseThis]
	local statsValue = player:WaitForChild("Boosts"):FindFirstChild(info.Title)

	if not statsValue or not info then
		warn("No Boost or info")
		return
	end

	local price = info.Price
	local currency = info.Currency
	local max = info.MaxPurchase
	local Purchased = info.Purchased

	if currency.Value >= price then
		currency.Value -= price
		statsValue.Value += info.Time
	end
end)

Edit: @ScxiptedShark Made an important edit to the server script, forgot to pass the player to the GetItems function :sweat_smile:

3 Likes

Im still geting the same error. I hate making this system :frowning:

2 Likes

What happens if you print the Items table returned by the GetItems function?

3 Likes

image

2 Likes