|
| 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 |
|
|
|
| 29 Jul 2015 11:51 PM |
uhh
Idk
but use Maps[i].Name? |
|
|
| Report Abuse |
|
|
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
|
  |
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 30 Jul 2015 12:38 AM |
| Thats wrong, instawin is the right one. |
|
|
| Report Abuse |
|
|
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 |
|
|
| |
|
|
| 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 |
|
|
| |
|
|
| 30 Jul 2015 12:55 AM |
| Do you mean you want to spam more? |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 30 Jul 2015 01:01 AM |
| I'm having issues, can you join me in a game |
|
|
| Report Abuse |
|
|
instawin
|
  |
| Joined: 04 Jun 2013 |
| Total Posts: 8777 |
|
| |
|
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 |
|
|
| |
|