Attempt to index nil with Instance

Yeah lol, i should listen to the professionals

1 Like

Ok, back to index nil with price, not table

1 Like

Server script:

local mod = require(game:GetService("ServerStorage").MerchantHandler)
local Remote = game:GetService("ReplicatedStorage"):FindFirstChild("Merchant").PotionPurchase


Remote.OnServerEvent:Connect(function(Player, purchaseThis)
		local Items = mod.GetItems(Player)
		local statsValue = Player:WaitForChild("Boosts"):FindFirstChild(purchaseThis)
		local info = Items[purchaseThis]
		if not statsValue or not info then warn("No Boost or info") end
		local price = info[purchaseThis].Price
		local currency = Player:WaitForChild("leaderstats"):FindFirstChild(info[purchaseThis].Currency.Value)

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

module replicated


Module Replicated

``` lua
local MerchantHandler = {}

local Player = game:GetService("Players").LocalPlayer

local LeaderstatsFolder = Player:WaitForChild("leaderstats")
local BoostsFolder = Player:WaitForChild("Boosts")

MerchantHandler.PotionPurchaseCooldown = 3600 -- (3600 = 1 Hour),  (86400 = 1 Day)

MerchantHandler.Items = {

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

}

function MerchantHandler.CreatePotionPurchaseFrame(name)
	local Template = script.Parent:WaitForChild("Potion1"):Clone()
	local gui = Player.PlayerGui:WaitForChild("Main"):WaitForChild("PotionMerchant")

	Template.Name = MerchantHandler.Items[name].Title
	Template.Icon.Image = MerchantHandler.Items[name].Image
	Template.PotionName.Text = MerchantHandler.Items[name].Title
	Template.Purchased.Text = MerchantHandler.Items[name].Purchased.."/"..MerchantHandler.Items[name].MaxPurchase
	Template.PriceLabel.Text = MerchantHandler.Items[name].Price.." "..MerchantHandler.Items[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

return MerchantHandler

Module ServerStorage

local MerchantHandler = {}


function MerchantHandler.GetItems(player)

	local LeaderstatsFolder = player:WaitForChild("leaderstats")
	local BoostsFolder = player:WaitForChild("Boosts")
	local Items = {

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

	}

	return Items
end


return MerchantHandler

What i’m getting from this error is Info/PurchaseThis is equal to nothing

Changed your server script to this:

local mod = require(game:GetService("ServerStorage").MerchantHandler)
local Remote = game:GetService("ReplicatedStorage"):FindFirstChild("Merchant").PotionPurchase


Remote.OnServerEvent:Connect(function(Player, purchaseThis)
		local Items = mod.GetItems(Player)
		local info = Items[purchaseThis]
		local statsValue = info and Player:WaitForChild("Boosts"):FindFirstChild(info.Title)
		if not statsValue then warn("No Boost or info")  return end
		local price = info.Price
		local currency = info.Currency

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

SO CLOSE!!!

1 MORE ERROR I THINK

ServerScriptService.Extra.PotionMerchant:13: attempt to compare number <= nil

I gtg now but it would be good if u could continue to resolve it for me for in the morning. Thanks!

Fixed it, you were trying to use :FindFirstChild with an instance again.

1 Like

@Katrist are you back yet?

Blockquote

Try printing purchaseThis and info.

1 Like

You didn’t open the table before you screenshotted.

1 Like

Alr lol, ill fix it now

Blockquote

@Katrist
image

Is there a value in your Boosts named Potion1?

1 Like

Potion 1 is a intvalue. But the name of the potion is rainbow hatch

image

Try my edited code.

You were searching for Potion 1 instead of Gem Potion.

1 Like

Omg it flipping works. Thank you so much!

Can you help me remove the serverstorage thing tho, it just complicates things


Also could i just remove this? i know ima get confused lol

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