local students = { {name = "Alice", score = 85}, {name = "Bob", score = 58}, {name =…
- User
local students = { {name = "Alice", score = 85}, {name = "Bob", score = 58}, {name = "Charlie", score = 91}, {name = "Diana", score = 74}, {name = "Edward", score = 66} } for i = 1,5 do local Oguzok = {} table.insert(Oguzok, students[i].score) print(Oguzok[2]) end
- Assistant
In your code, you're trying to access
Oguzok[2]within the loop after inserting only one element (the score of the student) into theOguzoktable. Since you're inserting each student's score one at a time into a newOguzoktable, it only contains one element in each iteration, which is atOguzok[1]. Therefore, attempting to accessOguzok[2]causes an issue because that index doesn't exist. To fix this, you should printOguzok[1]instead ofOguzok[2]. Here's the corrected code:lua