Hi! For most people, this should be easy. But I can't figure it out. I have been trying to get a random value from a table, then I want it to print. It says, attempt to call local 'SelectedGamemode' (a number value). Any help?
--Start local G1 = "Normal" local G2 = "FFA" local G3 = "2 People in!" local Gamemodes = { G1, G2, G3, } local SelectedGamemode = math.random(1, #Gamemodes) print('The selected Gamemode is... 'SelectedGamemode"!")
Nope. So then I try this:
--Start local G1 = "Normal" local G2 = "FFA" local G3 = "2 People in!" local Gamemodes = { G1, G2, G3, } local SelectedGamemode = math.random(#Gamemodes) --Change here print('The selected Gamemode is... 'SelectedGamemode"!")
Help is greatly appreciated!
It seems that SelectedGamemode will be a number ( max the length of the table Gamemode which would be 3 ) instead of the string you want it to be and I guess you don't want that to happen, so to get the actual gamemode name you'd need to go in the table and check what's on the value that math.random gave you
Basically for SelectedGamemode to give the actual name the variable would need to be changed to:
local SelectedGamemode = Gamemodes[math.random(#Gamemodes)]
So it would work fine, for example if math.random gave you the value 3, it would return the G3 variable which is: "2 People in!"
Also something I noticed is that you used print incorrectly, to add something to a string you should use ' .. '
print('The selected Gamemode is... 'SelectedGamemode"!")
would be:
print('The selected Gamemode is... '..SelectedGamemode.."!")
Hope that helped with your code! :D