local TeleportService = game:GetService("TeleportService") local gameID = (Place Id)
function onTouched(hit) local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player then TeleportService:Teleport(gameID, player) end end
script.Parent.Touched:connect(onTouched)
This is my script. Now how can I change it so that when Clicked teleports you to another game. I would appreciate if somebody would help me. Thanks.
Try this:
1 | local TeleportService = game:GetService( "TeleportService" ) |
2 | local PlaceID = -- GAME ID |
3 |
4 | script.Parent.ClickDetector.MouseClick:Connect( function (player) |
5 | TeleportService:Teleport(PlaceID, game.Players:WaitForChild(player.Name)) |
6 | end ) |
What I did is that I got the player's name by the function "MouseClick". Then I got it in game.Players and I teleport it.
Also, make sure to put this code in a SCRIPT (not in a localscript). That script should be in the CLICKING PART, and NOT the CLICK DETECTOR.
I hope this helped!
Try this script. :)
01 | local TeleportService = game:GetService( "TeleportService" ) |
02 |
03 | local Place = YOUR GAME ID |
04 |
05 | local player = game.Players.LocalPlayer |
06 |
07 |
08 |
09 | script.Parent.MouseButton 1 Click:connect( function () |
10 |
11 | TeleportService:Teleport(Place, player) |
12 |
13 | end ) |