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:
local TeleportService = game:GetService("TeleportService") local PlaceID = -- GAME ID script.Parent.ClickDetector.MouseClick:Connect(function(player) TeleportService:Teleport(PlaceID, game.Players:WaitForChild(player.Name)) 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. :)
local TeleportService = game:GetService("TeleportService") local Place = YOUR GAME ID local player = game.Players.LocalPlayer script.Parent.MouseButton1Click:connect(function() TeleportService:Teleport(Place, player) end)