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!