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:

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!

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

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)
0
It doesn't work damianbratonja 22 — 5y

Answer this question