generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Random map select

Previous Thread :: Next Thread 
StrategyGames is not online. StrategyGames
Joined: 02 Dec 2006
Total Posts: 3677
29 Jul 2015 11:48 PM
Hey all I haven't done much before with math.random before but I am experimenting as I am trying to make a map selecter.

this is what I have so far but I feel I have messed up completely as printing #maps I beleive would return a number, not a name.

How would I go about this?

function mapselect(mapname)
math.randomseed(tick())
local Maps = game.ServerStorage.Maps:GetChildren()
for i = 1, #Maps do
print(math.random(#Maps.Name))
mapname = #Maps.Name
return mapname
end
end
Report Abuse
PerilousDanger is not online. PerilousDanger
Joined: 21 Aug 2012
Total Posts: 3773
29 Jul 2015 11:51 PM
uhh

Idk



but use Maps[i].Name?
Report Abuse
instawin is not online. instawin
Joined: 04 Jun 2013
Total Posts: 8777
29 Jul 2015 11:51 PM
function mapselect(mapname)
math.randomseed(tick())
local Maps = game.ServerStorage.Maps:GetChildren()
local randMap = Maps[math.random(1, #Maps)]
print(tostring(randMap))
return randMap
end
Report Abuse
instawin is not online. instawin
Joined: 04 Jun 2013
Total Posts: 8777
29 Jul 2015 11:52 PM
forgot to remove the mapname parameter you made


you won't need it

to use a random map with my modified version, just do

local yourRandomMap = mapselect()
Report Abuse
StrategyGames is not online. StrategyGames
Joined: 02 Dec 2006
Total Posts: 3677
30 Jul 2015 12:01 AM
Thanks for your help,
Just wondering if you can run me through one thing quickly, what is tostring?
print(tostring(randMap))

In the Maps model I have numerous map models, just making sure it will return the right model so I can access it in another function with

mapselect()
if mapselect == "Yavin 4" then
_G.Map_Yavin4()


Would that work? would it run the mapselect function and then have the value returned so it can be used in if mapselect ==

Report Abuse
instawin is not online. instawin
Joined: 04 Jun 2013
Total Posts: 8777
30 Jul 2015 12:20 AM
1. tostring converts its argument into a string

the reason why i used tostring is because i was going to print an object, and i think that would error but idek. if you wanted to be safe, just print the map's name.

"In the Maps model I have numerous map models, just making sure it will return the right model so I can access it in another function with

mapselect()
if mapselect == "Yavin 4" then
_G.Map_Yavin4()


Would that work? would it run the mapselect function and then have the value returned so it can be used in if mapselect =="

if you wanted to check which map is returned when you call mapselect, you will need to check the name of the map model that was selected.

local randMap = mapselect()
if randMap.Name == "Yavin 4" then
_G.Map_Yavin4()
elseif randMap.Name == "Another Map Name" then
_G.LoadAnotherMapOrWoteverM8
end

Report Abuse
StrategyGames is not online. StrategyGames
Joined: 02 Dec 2006
Total Posts: 3677
30 Jul 2015 12:28 AM
so would this work?

function mapselect(mapname)
math.randomseed(tick())
local Maps = game.ServerStorage.Maps:GetChildren()
local randMap = Maps[math.random(1, #Maps)]
print(tostring(randMap))
return randMap
end


function myGame:Start()
print("starting game")
if script.NumPlayer.Value > 1 then
wait(5)
local Map = game.workspace:findFirstChild("Map")
local MapValue = script.Map.Value
script.Map.Value = "None"
if Map ~= nil then
Map:remove()
end
mapselect()
local randMap = mapselect()
if randMap.Name == "Yavin 4" then
_G.Map_Yavin4()
end
Report Abuse
instawin is not online. instawin
Joined: 04 Jun 2013
Total Posts: 8777
30 Jul 2015 12:32 AM
function mapselect()
math.randomseed(tick())
local Maps = game.ServerStorage.Maps:GetChildren()
local randMap = Maps[math.random(1, #Maps)]
print(tostring(randMap))
return randMap
end


function myGame:Start()
print("starting game")
if script.NumPlayer.Value > 1 then
wait(5)
local Map = workspace:FindFirstChild("Map")
local MapValue = script.Map.Value
script.Map.Value = "None"
if Map ~= nil then
Map:Destroy()
end
local randMap = mapselect()
if randMap.Name == "Yavin 4" then
_G.Map_Yavin4()
end
Report Abuse
instawin is not online. instawin
Joined: 04 Jun 2013
Total Posts: 8777
30 Jul 2015 12:36 AM
>local Map = workspace:FindFirstChild("Map")

just saying, aren't the names of your maps unique, such as something like "Yavin 4", not simply "Map"?
Report Abuse
HorribleRemakes is not online. HorribleRemakes
Joined: 24 Jul 2015
Total Posts: 16
30 Jul 2015 12:38 AM
Thats wrong, instawin is the right one.
Report Abuse
instawin is not online. instawin
Joined: 04 Jun 2013
Total Posts: 8777
30 Jul 2015 12:38 AM
i'd just recommend you store your map in a model named "MapHolder" in workspace, and at the beginning of your game, just do this


local mapHolder = workspace:FindFirstChild("MapHolder")

for i, v in pairs(mapHolder:GetChildren()) do
v:Destroy()
end
Report Abuse
HorribleRemakes is not online. HorribleRemakes
Joined: 24 Jul 2015
Total Posts: 16
30 Jul 2015 12:40 AM
^
Report Abuse
StrategyGames is not online. StrategyGames
Joined: 02 Dec 2006
Total Posts: 3677
30 Jul 2015 12:52 AM
Be quite Horrible, you make no sense.

And my maps all have unique names but in the map function it puts it in the workspace and renames it to Map :)
Report Abuse
HorribleRemakes is not online. HorribleRemakes
Joined: 24 Jul 2015
Total Posts: 16
30 Jul 2015 12:53 AM
Quite? You mean quiet?
Report Abuse
StrategyGames is not online. StrategyGames
Joined: 02 Dec 2006
Total Posts: 3677
30 Jul 2015 12:55 AM
Do you mean you want to spam more?
Report Abuse
instawin is not online. instawin
Joined: 04 Jun 2013
Total Posts: 8777
30 Jul 2015 12:55 AM
very well, then try out what i gave you

i'd still recommend my method but wotever xdd
Report Abuse
StrategyGames is not online. StrategyGames
Joined: 02 Dec 2006
Total Posts: 3677
30 Jul 2015 01:01 AM
I'm having issues, can you join me in a game
Report Abuse
instawin is not online. instawin
Joined: 04 Jun 2013
Total Posts: 8777
30 Jul 2015 01:04 AM
what is the issue?
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
30 Jul 2015 01:08 AM
local maps = game.ServerStorage.Maps:GetChildren()

local ranMap = maps[math.random(1,#maps)]

if ranMap.Name == "Map1" then
ranMap:Clone().Parent = workspace
end


"Talk is cheap. Show me the code." - Linus Torvalds
Report Abuse
StrategyGames is not online. StrategyGames
Joined: 02 Dec 2006
Total Posts: 3677
30 Jul 2015 02:03 AM
Bit late there :P
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image