Ok so I have a script so when a map loads (The map is randomly chosen each round)
how can I teleport those players to the map that is randomly chosen?
You need to have a folder of spawns (invisible, noncancollide parts) that the players can be teleported to inside of the map. Randomly assign the players to be teleported to the spawns when the map is chosen.
So how could I teleport them to an assigned spawn inside the map?
Use their HumanoidRootPart, and Position, or CFrame it to positions on the map. Like this:
for a,b in pairs (game.Players:GetPlayers()) do
local spawn = map.Spawns:GetChildren(map.Spawns:GetChildren()[math.random(0,#map.Spawns:GetChildren())]); -- pick a random spawn
local char = b.Character or b.Character:Wait();
char.HumanoidRootPart.CFrame = spawn.CFrame;
end
not sure how much of that is valid lua, you’re going to need to change some of it.
Important parts:
for a,b in pairs (game.Players:GetPlayers()) do
local char = b.Character or b.Character:Wait();
char.HumanoidRootPart.Position = Vector3.new(x,y,z);
end
Do something like this:
local mapSpawn = map.Spawn
for _, player in pairs(game.Players:GetChildren()) do
player:MoveTo(mapSpawn.Position)
end
This will make the player manually move, so they’ll basically walk there. This method is invalid.
You’re thinking of Humanoid:MoveTo()
. Doing Player:MoveTo()
will automatically bring the player to that position.
So the code would be?
if chosenChapter == game.ReplicatedStorage.Chapters.Chapter1Real then
game.Players.LocalPlayer.position = -188.73, 1.5, -186.593
end if chosenChapter == game.ReplicatedStorage.Chapters.Chapter1Real then
game.Players.LocalPlayer.position = -188.73, 1.5, -186.593
end
I know thats completely wrong I just need help with this.
This isn’t a documented API?
30chars
Negative. For one don’t move the player on the client like that, do it on the server. Two, Use Position = Vector3.new(x,y,z)
Recommend you reading over this guide
Why, because FIlteringEnabled
Whoops I pasted it twice! My bad.
Yeah, I guess that works, however, I think the intended method is using the HumanoidRootPart, though, I guess either way works. I just think its safer as moving certain parts of the body without moving the HRP will kill the player.
I personally use the :MoveTo() method because as stated in the Model:MoveTo() api, it avoids collisions. If I were to move the HumanoidRootPart to the position of a flat part, the player could possibly clip inside the ground, but :MoveTo() avoids that, placing them on top every time without needing to add vectors.
Edit: Added api hyperlink because this was marked as solution