The error actually explains what goes wrong kinda well.
You’re trying to set the Text property to nil, which naturally doesn’t make sense because nil can’t represent text. Only strings can (string expected, got nil).
If you’d tested your math, you’d have seen that it’s wack. For the levels 1 to 10, it gives these “rank numbers”:
Where the number before the arrow is the level and the number after is the rank. Right now you’re giving players 5 ranks per level instead of one rank for every 5th level. There’s no rank number 25, so when you try to set the Text property to ranks[25], you’re trying to set Text to nil. Hence the error.
Here’s the actual rounding function you want:
math.ceil(i/5)
Yeah that simple. You can test the two approaches like this:
for i = 1, 10 do
print(i .. " -> " .. ( math.floor(i + 0.5) * 5 ))
end
for i = 1, 15 do
print(i .. " -> " .. math.ceil(i/5))
end
It’s often fine to fudge things by “just getting it to work” (adding a tostring in this case), but it’s usually better to really understand what goes wrong so you can fix the underlying cause.