Hello, In response to your comment, here is a way in which you can teleport players to a brick of your choice.
So basically, in my game, I have it so there is only ONE spawn, where all the payers spawn at but the camera is fixed in another spot, and the fiddle with the GUIs until they come upon the "Deploy Button", which is when the camera is set back to normal and they teleport to one of the parts which I called "Spawn1", "Spawn2", etc until "Spawn8".
For the other team, I did the exact script but I made new spawns and changed their names to "BSpawn1" etc. And in the script I changed the variable to
local spawnpart = game.Workspace:FindFirstChild(BSpawn..math.Random(1,8))
Ignore the camera bit, because in my game I am working on, I have the camera fixed in place and when you press deploy, the camera goes back to normal.
I can explain it too.
So first I defined the variables. Keep the camera bit just to prevent any camera glitches when you teleport.
Then when you press the button, (define the all the spawns parts 1 - 8) If you want only one block then just do
local spawnpart = game.Workspace.Spawn1
then you want to define the HumanoidRootPart. This is the main part of the humanoid and is needed to teleport players.
After defining it, you want to teleport it by setting it's CFrame to a CFrame.new(x,y,z). The XYZ positions you need are the ones from the part(s) you're gonna teleport the player to. But you want to add a few extra on the Y value, so they won't glitch into the ground or whatever.
so it would be :
humanoidRootPart.CFrame = CFrame.new(spawnpart.Position.X, spawnpart.Position.Y + 5, spawnpart.Position.Z)
As you can see, an extra 5 studs was added to help prevent my players from getting stuck into the ground.
This is the script I used. Please do change it to your needs. This occurs when I press a button, if you want it to occur another way, research it, A good place to look is the Wiki.
local players = game:GetService("Players")
local player = players.LocalPlayer
local button = script.Parent
local Camera = game.Workspace.CurrentCamera
button.MouseButton1Click:Connect(function()
local spawnpart = game.workspace:FindFirstChild("Spawn"..math.random(1,8))
local humanoidRootPart = player.Character.HumanoidRootPart
humanoidRootPart.CFrame = CFrame.new(spawnpart.Position.X, spawnpart.Position.Y + 5, spawnpart.Position.Z)
end)
button.MouseButton1Click:Connect(function()
Camera.CameraType = 'Custom'
Camera.CameraSubject = player.Character
end)
I hope this was useful, Thanks.
Tony
Please Accept this answer if it was good and useful for you.
3 comments
I had this issue. in the end what I did was, just has one spawn where all the players spawn at the start of the game, and when the player presses a button when they want to join a team, I would set their team to that, and then move their HumanoidRootPart.CFrame one of the parts called Spawn. If you would like a script, please tell me
My script is when you press a button (a deploy button) and they teleport to one of the parts I called (spawn part) and they teleport to a random one
Oh, that would be awesome! I would love that script, thank you.