I want to teleport randomPlayer to GameAreaSpawn in my game:
local Status = game.ReplicatedStorage.Status
local StatusTitle = game.ReplicatedStorage.StatusTitle
local Mazes = game.ServerStorage.Mazes:GetChildren()
local maze = Mazes[math.random(1, #Mazes)]:Clone()
local GameAreaSpawn = game.Workspace.GameArea.GameAreaSpawn
local Players = game:GetService("Players"):GetPlayers()
local randomPlayer = Players[math.random(1, #Players)]
local function startIntermission()
StatusTitle.Value = "Intermission"
for i = 5, 0, -1 do
wait(1)
Status.Value = i
end
end
local function startGame()
wait(1)
StatusTitle.Value = "Game"
for i = 5, 0, -1 do
Status.Value = i
wait(1)
end
end
startIntermission()
maze.Parent = game.Workspace
-- Teleport random player here
startGame()
You’ll have to loop through the players, like this!
for Index, Player in ipairs(Players) do -- Loops through the players 1 by 1.
Player.Character:MoveTo(GameAreaSpawn.Position) -- Moves the character to the given Position.
end
You can’t move Player, you’ll first have to get it’s Character, and then move the character, but that’ll work too. Also I’m not sure if he wants to move all Players, or just 1 random Player.
--//Services
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--//Variables
local Status = ReplicatedStorage.Status
local StatusTitle = ReplicatedStorage.StatusTitle
local Mazes = ServerStorage.Mazes:GetChildren()
local maze = Mazes:GetChildren()[math.random(1, #Mazes)]:Clone()
local GameAreaSpawn = workspace.GameArea.GameAreaSpawn
local Players = Players:GetPlayers()
local randomPlayer = Players[math.random(1, #Players)]
--//Functions
local function startIntermission()
StatusTitle.Value = "Intermission"
for i = 5, 0, -1 do
task.wait(1)
Status.Value = i
end
end
local function startGame()
task.wait(1)
StatusTitle.Value = "Game"
for i = 5, 0, -1 do
Status.Value = i
task.wait(1)
end
end
--//Initialization
startIntermission()
maze.Parent = game.Workspace
randomPlayer.Character:MoveTo(GameAreaSpawn.Position)
startGame()
--//Services
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--//Variables
local Status = ReplicatedStorage.Status
local StatusTitle = ReplicatedStorage.StatusTitle
local Mazes = ServerStorage.Mazes:GetChildren()
local maze = Mazes[math.random(1, #Mazes)]:Clone()
local GameAreaSpawn = workspace.GameArea.GameAreaSpawn
local PlayerTable = Players:GetPlayers()
local randomPlayer = PlayerTable[math.random(1, #PlayerTable)]
--//Functions
local function startIntermission()
StatusTitle.Value = "Intermission"
for i = 5, 0, -1 do
task.wait(1)
Status.Value = i
end
end
local function startGame()
task.wait(1)
StatusTitle.Value = "Game"
for i = 5, 0, -1 do
Status.Value = i
task.wait(1)
end
end
--//Initialization
startIntermission()
maze.Parent = game.Workspace
randomPlayer.Character:MoveTo(GameAreaSpawn.Position)
startGame()