Why am i getting this error?

So the table is being retrieved correctly, in that case what’s the value of purchaseThis?

3 Likes

It is the potion that you purchase

2 Likes

When firing the PotionPurchase remote, what data are you sending to the server? If you’re sending as an example “Potion 1” instead of “Potion1” it will result in info being nil which will cause the error to show up

3 Likes

Im not sure, like ive stated before. I cant code lol

3 Likes

Well I’m quite confused as to what might be causing this problem to occur, this will take a while before I can finish testing unfortunately

3 Likes

No worries! There is no rush.

Blockquote

3 Likes

Sorry it took me 1 hour to notice, but I realised the cause of the problem: In the FireServer we’re sending both the player an the name of the potion. There’s no need to send the player to the server since OnServerEvent automatically has the player as its first parameter, so currently we were indexing the Items table with the player instead of the potion’s name which is why it kept resulting in nil

1 Like

Thanks! so where would i apply these changes?

1 Like

In the module like so:

-- 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(name)
	end)
end

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

return MerchantItems
1 Like

Tysm! It works.

I may commission you if your up to it fin the future as i would like to expand on this system.

Thanks :smiley:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.