Trouble with a for loop

Hey there,

I am currently creating a game and it has a shop system, so i made a table with the minimum and the max amount of said product the player can buy, but when the player goes to buy said product it tells me to input a proper answer.

The Script:

local amount = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} -- Table with the max and min amount of product the player can buy

script.Parent.MouseButton1Click:Connect(function()
	for i, v in pairs(amount) do
		if script.Parent.Parent.HowMany.Text == v then -- I assume there is something wrong here?
			print("Purchasing...")
		else
			print("Please input a correct amount...") -- This prints 10 times
		end
	end
end)

Thanks! :slight_smile:

Lua won’t allow you to compare a string with a number. Use tonumber() like so…

if tonumber(script.Parent.Parent.HowMany.Text) == v then

Also, make sure you have the “Console” window open. It will show you script errors.

2 Likes

Try this:

if script.Parent.Parent.HowMany.Text == tostring(v) then

1 Like