Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I make it when clicked teleport to another place? (With ClickDetector)

Asked by 5 years ago

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.

0
sorry but which one do you want, when touched(.Touched) or when clicked (ClickDetector) RBLXNogin 187 — 5y
0
It even says in the title... damianbratonja 22 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

Try this:

1local TeleportService = game:GetService("TeleportService")
2local PlaceID = -- GAME ID
3 
4script.Parent.ClickDetector.MouseClick:Connect(function(player)
5    TeleportService:Teleport(PlaceID, game.Players:WaitForChild(player.Name))
6end)

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!

0
Thank you very much indeed damianbratonja 22 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

Try this script. :)

01local TeleportService = game:GetService("TeleportService")
02 
03local Place = YOUR GAME ID
04 
05local player = game.Players.LocalPlayer
06 
07 
08 
09script.Parent.MouseButton1Click:connect(function()
10 
11TeleportService:Teleport(Place, player)
12 
13end)
0
It doesn't work damianbratonja 22 — 5y

Answer this question