Hiya Developers!
I have a script here which randomly picks a map and teleports the players to the teleport pads.
Is there anyway to teleport players to different parts depending on the map chosen?
Example: A race map is selected, we teleport the players to a part above the car instead of teleporting them to the normal parts that every other map teleports to.
Here is the script:
local choose =
math.random(#mapselect)
curnum = 0
for i =1,#mapselect do
curnum = curnum +1
if curnum == choose then
mapselect[i]:Clone().Parent = workspace
curmap = mapselect[i].Name
s.Value = "We'll Be Playing "..mapselect[i].Name
end
end
wait(3)
local plrs = game.Players:GetChildren()
for i = 1,#plrs do
local num = math.random(1,32)
plrs[i].Character.Head.CFrame = CFrame.new(workspace.Teleports["Part"..num].Position)
plrs[i].Character.Parent = workspace.Ingame
end
Any help would be apricated, thanks.
Give the teleport parts specific names and position them in the desired locations for each map.
How do i check the map that was selected for the different teleports? Because for example, say a Obby map was chosen i don’t want the players to teleport to the previous teleports from the Car map.
Are all maps loaded into the workspace from the start?
No, there all into ReplicatedStorage
So when the map is cloned into the workspace shouldn’t only the teleports for that map exist?
The teleports are already set in workspace, the map will spawn exactly where the teleport pads are
local replStorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local maps = {"samplemap1", "samplemap2", "samplemap3"}
local randNum = math.random(1, #maps)
local randMap = replStorage.maps[randNum]
randMap:Clone().Parent = workspace
local mapName = randMap.Name
s.Value = "The chosen map is "..mapName.."!" --not sure what the instance named s is
wait(3)
local plrs = game.Players:GetChildren()
for _, v in pairs(plrs) do
local num
if randNum == 1 then
num = math.random(x, y) --set the range of valid teleports for the first map
elseif randNum == 2 then
num = math.random(x, y) --set the range of valid teleports for the second map
end
v.Character.Head.CFrame = CFrame.new(workspace.Teleports["Part"..num].Position)
v.Character.Parent = workspace.Ingame
end
You’ll need to do some slight tweaking so that it fits your game but this should work.
1 Like
Thanks alot, this will help a bunch!