Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Random map choosing and MoveTo()?

Asked by 10 years ago

Could you tell me if this line of script could work and teleport all players to a random map, but not teleport them to different maps in the same round?

local coords1 = {Vector3.new(1,1,1), Vector3.new(1,1,2)} --example
local coords2 = {Vector3.new(2,2,2), Vector3.new(2,2,3)}
local coords3 = {Vector3.new(3,3,3), Vector3.new(3,3,4)}
local map1 = coords1[math.random(#coords1)]
local map2 = coords2[math.random(#coords2)]
local map3 = coords3[math.random(#coords3)]

local randMap = map1,map2,map3[math.random(map1,map2,map3)]

for i,v in pairs(game.Players:GetPlayers()) do 
    v.Character:MoveTo(randMap)
end

Would that choose a random map and spawn them at random coordinates and all of them go to the same map or not?

If it wouldn't can you tell me how I would make it choose a random map and random coords and spawn players at the same map?

0
randMap is not a position if the object has a property that's called Position or refers to then you will be able to use the :MoveTo() method. Kozero 120 — 10y

1 answer

Log in to vote
1
Answered by 10 years ago

I don't think you're picking a random map the right way. If you want to clone a map and add it to Workspace, you can do this:

local maps = {  --table containing all the maps located in ServerStorage
    game.ServerStorage.Map1:clone(),
    game.ServerStorage.Map2:clone()
}

function pickMap()
    return maps[math.random(#maps)]:clone()
end

local map = pickMap() --this returns a new map that you can parent to Workspace.
map.Parent = Workspace --set the parent to Workspace

--Now you need to teleport all players to a random position.  To do this, I put a model inside each map called 'teleportParts'.  It contains multiple parts.  Each player will be teleported to a random part inside the teleportParts model.  NOTE: The number of parts in teleportParts must be greater than the number of players

local tParts = map.teleportParts:GetChildren()
local players = game.Players:GetPlayers()
for i, part in pairs(tParts) do
    player[i].Character:MoveTo(part.Position) --move each player to a different part
end
0
I'm just trying to get it to pick a random table of vector3's, and then teleport them to any one of those random vector3's systematicaddict 295 — 10y
0
Your script is all fine until you get to the last section, where you loop through parts when you should have looped through Players and thus you didn't define the variable player. Archonious2 160 — 10y
0
@Foreverdev Your script worked, I had to fix a bunch of errors, and tweak it so it worked for my script, took about 30 minutes :\, but thanks. I'll thumbs up your answer and accept it. systematicaddict 295 — 10y
Ad

Answer this question