Attempt to index nil with Instance

You’re not supposed to send the player in :FireServer, as .OnServerEvent automatically receives the player.

Code:

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

You also can only use a string inside :FindFirstChild, but you’re using a whole instance, which doesn’t work.

4 Likes

Thanks! But in the serverscript im still getting this error:

3 Likes

Yeah, I didn’t fix this problem for you:

Because I’m not sure how your layout works.

4 Likes

Can you try and help me out? sorta desperate lol

Where am i using :FindFirstChild(“”)?

3 Likes

Could you first off tell me what script is PotionMerchant?

4 Likes

A serverscript which handles the remote event - Checks the currency of the purchased item and price and awards time if price >= currency.Value

image

3 Likes

Can you try printing purchaseThis?

4 Likes

image

CURRENT ERROR: Serverscriptservice


2 Likes

Hello? Are you there @Katrist

type or paste code here
2 Likes

Try my edited client code.

3 Likes

Where?

type or paste code here
1 Like

I edited my client code.

2 Likes

Argument 1 missing or nil:
local statsValue = Player:WaitForChild(“Boosts”):FindFirstChild(purchaseThis.Potion)

2 Likes

I think its using the table, not the boost itself

Yeah “Attempted to index nil with table”

1 Like

That was not the code I sent.

2 Likes

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.Potion)
		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(MerchantHandler.Items[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
2 Likes

I didn’t tell you to change your Server script.

2 Likes

I found an issue.


“PurchaseThis” was just the contents of the table. It wasn’t referencing the potion Data Type(NumValue)

image
Now it references the actual potion

1 Like

In my other code, I’m sending over a string, not the table. That’s what my edit was.

Can you please just listen and copy and paste the code I used, keeping your original server script too?

2 Likes

Yeah lol, i should listen to the professionals

1 Like