Only the first Print is printed and the rest does not work, can you help me solve it please, I am new to programming and a Rookie
local targetNumber = math.random(1, 100)
local attempts = 0
local guess = 0
print("Welcome to the Guessing Game. I'm thinking of a number between 1 and 100.")
while guess ~= targetNumber do
io.write("Enter your guess: ")
guess = tonumber(io.read())
attempts = attempts + 1
if guess < targetNumber then
print("Too low. Try again!")
elseif guess > targetNumber then
print("Too high. Try again!")
end
end
print("Congratulations! You guessed the number " .. targetNumber .. " in " .. attempts .. " attempts.")
To be honest, I don’t use LUA outside of roblox, so I’m not really clear on io’s capabilities, but if this is just a simple game in the roblox output, you can just replace the io.write with print(), and the guess = tonumber(io.read()) to math.random(1,100), or whatever interval you want.
io.write and io.read are input/outputs in Lua, they don’t exist in Roblox Lua though, but you can make input/outputs using TextBox that you can input text inside, and print as the output