PROBLEM #1
On line 5 of your script, you're telling the function math.random() to choose a number between 1 and a table of all your maps. You're telling the function to choose a number between a number and table. This will result in an error, because the function expects both a and b to be number values.
HOW TO FIX PROBLEM #1
If you have a table, you can get the count of the table by prefixing the table with a "#"
For Example,
local myTable = {"a",2,"hi"}
print(#myTable)
To fix your script, simply prefix AllMaps (inside of math.random) with a "#"
local Maps = {}
local AllMaps = RStorageService.Maps:GetChildren()
for i = 0, 3 do
local map = (AllMaps[math.random(1, #AllMaps)]).Name
for index, v in pairs(Maps) do
if v == map then
i = i - 1
return
end
end
table.insert(Maps, map)
end
print(Maps[1], Maps[2], Maps[3])
If this doesn't fix your problem, I dont have any other solutions for you.
Glad I could help!
-ReadyHappiness
PROBLEM #2
"Yes my error is fixed, but now my print in line 15 return (nil, nil, nil).. Do you know why?"
-NiniBlackJackQc
Line 15 of your code goes something like this:
print(Maps[1], Maps[2], Maps[3])
On line 12, your code table.insert(Maps, map) is correct, because the function's format, table.insert(table,item) fits.
But you only did this once for the one map out of the 3 given.
So of course .., Maps[2], Maps[3].. would print nil. So why is ..Maps[1],.. printing nil?
HOW TO FIX PROBLEM #2 - RECCOMMENDATION
Right now, line 15 prints this: nil nil nil
This is odd, because object 1 of Maps SHOULD be the map.
I do not know why Maps[1] prints nil. But here's a reccommendation.
Use the map variable instead of Maps[1]. Unless there's a reason that the map is inserted into the Maps table, this alteration should solve your problem.
If you need further help, comment back on this answer.
Glad to help ya, again,
-ReadyHappiness
5 comments
Yes my error is fixed, but now my print in line 15 return (nil, nil, nil).. Do you know why?
I will try to figure this out. Happens to me alot where i fix one thing and another's cap pops off.
P.S. Is the script your running your code in a "LocalScript" or a "Script?"
"Script", but I have fix my problem in remove "for index, v in pairs(Maps) do".. Thanks for answers:)
Okay, glad I could help you!