Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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.

2 comments

0

sorry but which one do you want, when touched(.Touched) or when clicked (ClickDetector)

0

It even says in the title...

2 answers

✓ Accepted answer

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!

1 comment

0

Thank you very much indeed

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)

1 comment

0

It doesn't work

This discussion is preserved as it was. New answers, comments, and votes are closed.