I want to make a teleport for when you touch a brick that it teleports you to my friends place. Please help! (Also It Isn't To Get Him Visits We just Want To Reduce Lag In My Game)
Here script, change the ID of your friend's place's id.
1 | function onTouched(hit) |
2 | local player = game.Players:GetPlayerFromCharacter(hit.Parent) |
3 | if player then |
4 | game:GetService( "TeleportService" ):TeleportToSpawnByName(*IDHERE*, "Your friend's place's spawnname" , player) |
5 | end |
6 | end |
7 |
8 | script.Parent.Touched:connect(onTouched) |
Here is a great wiki article that can help you.
But here is my interpretation:
1 | local teleportid = 0 --Put the place ID here |
2 | local player = "Telamon" --put which player to teleport |
3 | game:GetService( 'TeleportService' ):Teleport(teleportid, game.Players:FindFirstChild(player)) |
However, if you want it to teleport everyone in the game, here is the proper code:
1 | local teleportid = 0 --Put the place ID here |
2 | for i,v in pairs (game.Players:GetPlayers()) do |
3 | game:GetService( 'TeleportService' ):Teleport(teleportid, v) |
4 | end |
Lastly, if you want it where everytime someone joins, it teleports them, here is how it would go:
1 | local teleportid = 0 --Put the place ID here |
2 | game.Players.PlayerAdded:connect( function (plr) |
3 | game:GetService( 'TeleportService' ):Teleport(teleportid, plr) |
4 | end ) |
Hope that helped!