I am working with an RPG Kit and I keep getting this error...

09:14:48.178 - Players.Player1.PlayerGui.ArmorShopGUI.TextLabel.ShopScript:74: attempt to index a nil value 09:14:48.178 - Stack Begin 09:14:48.179 - Script 'Players.Player1.PlayerGui.ArmorShopGUI.TextLabel.ShopScript', Line 74 - global CheckArmor 09:14:48.179 - Script 'Players.Player1.PlayerGui.ArmorShopGUI.TextLabel.ShopScript', Line 83 - global UpdateButtons 09:14:48.179 - Script 'Players.Player1.PlayerGui.ArmorShopGUI.TextLabel.ShopScript', Line 119

This is the script:

local Player = Game.Players.LocalPlayer
local GUI = Player.PlayerGui:WaitForChild("ArmorShopGUI")
local Tooltip = GUI:WaitForChild("Tooltip")

GUI:WaitForChild("TextLabel")

local buttons = {"Armor1", "Armor2", "Armor3", "Armor4", "Armor5", "Armor6", "Armor7", "Armor8", "Armor9"} --Add more if you intend to add more armors. Don't forget to insert more into the other tables too.
local armorVarNames = {"UnlockedLeather", "UnlockedChainmail", "UnlockedBronze","UnlockedIron", "UnlockedSteel", "UnlockedMithril", "UnlockedAdamant", "UnlockedDemonic", "UnlockedBone"} --This will be searched up in 'Game.ReplicatedStorage.ARMORS'.
local prices = {50, 100, 300, 1000, 2500, 6000, 15000, 50000, 200000}

--Will be displayed on tooltip.
local armorNames = {
	"Leather armour",
	"Chainmail armour",
	"Bronze armour",
	"Iron armour",
	"Steel armour",
	"Mithril armour",
	"Adamant armour",
	"Demonic armour",
	"Bone armour"
}
local armorDesc = {
	"This armour is made with leather.",
	"This armour is made with iron chains linked together.",
	"Bronze ingots were hammered to make this. It's cheap but it might suffice.",
	"Iron ingots were hammered to make this.",
	"This finely crafted steel armour is the choice for adventurers.",
	"Elite warriors wore this armour. It's lightweight and strong.",
	"This armour is made out of Adamantium, an indestructible metal.",
	"This fierce armour were worn by demons but you can wear it too. If you have this.",
	"This armor is finely crafted with the bones of fallen foes!"
}

function commas(num)
  	assert(type(num) == "number" or type(num) == "string")
  
 	local result = ""

	-- split number into 3 parts, eg. -1234.545e22
	-- sign = + or -
	-- before = 1234
	-- after = .545e22
  	local sign, before, after = string.match(tostring(num), "^([%+%-]?)(%d*)(%.?.*)$")

  	-- pull out batches of 3 digits from the end, put a comma before them
	while string.len(before) > 3 do
  		result = "," .. string.sub(before, -3, -1) .. result
		before = string.sub(before, 1, -4)  -- remove last 3 digits
	end -- while

  	-- we want the original sign, any left-over digits, the comma part,
  	-- and the stuff after the decimal point, if any
	return sign .. before .. result .. after
end -- function commas

function MouseOver(armorName, armorDesc, armorPrice)
	Tooltip.ArmorName.Text = armorName
	Tooltip.ArmorDesc.Text = armorDesc
	Tooltip.ArmorPrice.Text = commas(armorPrice) .. " Gold"
	Tooltip.Visible = true
end

function MouseMoved(X, Y)
	Tooltip.Position = UDim2.new(0, X+40, 0, Y)
	Tooltip.Visible = true
end

function MouseOff()
	Tooltip.Visible = false
end

function CheckArmor(armor)
	if Player.UnlockedArmor:FindFirstChild(armor).Value == true then
		return true
	else
		return false
	end
end

function UpdateButtons()
	for i = 1, #buttons do
		if CheckArmor(armorVarNames[i]) == true then
			GUI.TextLabel:FindFirstChild(buttons[i]).BackgroundTransparency = 0.6
			GUI.TextLabel:FindFirstChild(buttons[i]).TextTransparency = 0.5
		else
			GUI.TextLabel:FindFirstChild(buttons[i]).BackgroundTransparency = 0
			GUI.TextLabel:FindFirstChild(buttons[i]).TextTransparency = 0	
		end
	end	
end

function BuyArmor(armor, price)
	if Player.UnlockedArmor:FindFirstChild(armor).Value == false then
		if Player.leaderstats.Gold.Value >= price then
			Player.leaderstats.Gold.Value = Player.leaderstats.Gold.Value - price
			Player.UnlockedArmor:FindFirstChild(armor).Value = true
			h = Instance.new("Hint", Player.PlayerGui)
			h.Text = "Thank you for purchasing!"
			Game:GetService("Debris"):AddItem(h, 3)
		else
			h = Instance.new("Hint", Player.PlayerGui)
			h.Text = "Sorry, you do not have enough gold to purchase this."
			Game:GetService("Debris"):AddItem(h, 3)			
		end
	else
		h = Instance.new("Hint", Player.PlayerGui)
		h.Text = "You already have this! I wonder why you are trying to buy more than one, eh?"
		Game:GetService("Debris"):AddItem(h, 3)		
	end
end

for i = 1, #buttons do
	GUI.TextLabel:WaitForChild(buttons[i])
end

for i = 1, #buttons do
	GUI.TextLabel:FindFirstChild(buttons[i]).MouseButton1Click:connect(function() BuyArmor(armorVarNames[i], prices[i])end)
	GUI.TextLabel:FindFirstChild(buttons[i]).MouseEnter:connect(function() MouseOver(armorNames[i], armorDesc[i], prices[i]) UpdateButtons() end)
	GUI.TextLabel:FindFirstChild(buttons[i]).MouseMoved:connect(MouseMoved)
	GUI.TextLabel:FindFirstChild(buttons[i]).MouseLeave:connect(MouseOff)
end

UpdateButtons()

There is also another error in the same script (nil value) The error is: 09:14:48.059 - Players.Player1.PlayerGui.ArmorShopGUI.TextLabel.ShopScript:94: attempt to index a nil value 09:14:48.059 - Stack Begin 09:14:48.059 - Script 'Players.Player1.PlayerGui.ArmorShopGUI.TextLabel.ShopScript', Line 94 - global BuyArmor 09:14:48.060 - Script 'Players.Player1.PlayerGui.ArmorShopGUI.TextLabel.ShopScript', Line 118 09:14:48.060 - Stack End

I appreciate any help, I am trying to make a game and I can't if this error is there. Thanks!

1 comment

0

please talk to the maker of the kit. we dont fix free models