Teleport script not working

I made a quick teleport script for my game. If you click it, you get teleported to another place. My problem is that it doesn’t work. I tried making it print something so I can test it in studio, but it doesn’t do it. Can someone check what’s wrong with my code?

local TeleportService = game:GetService("TeleportService")
local part = script.Parent
local clickDetector = part.ClickDetector
 
function onMouseClick(hit)
	local char = hit.Parent
	local player = game.Players:GetPlayerFromCharacter(char)
	print("clickedYeah")
	TeleportService:Teleport(5181582210, player)
	print("clickedYeah")
end

Well

  • You didn’t connect the onMouseClick function

  • The Player is already passed when using the ClickDetector's MouseClick Event

Try this:

local TeleportService = game:GetService("TeleportService")
local part = script.Parent
local clickDetector = part.ClickDetector
 
function onMouseClick(Player)
	print("clickedYeah")
	TeleportService:Teleport(5181582210, Player)
	print("clickedYeah")
end

clickDetector.MouseClick:Connect(onMouseClick)
1 Like

this is my first time using ClickDetectors, so I didn’t know this. Thanks!

1 Like