Teleporting Troubles!

Hello, im new to Lua so sorry if this is a super obvious question, but why does this code not work

local TeleportService = game:GetService("TeleportService")
local player = game.Players.LocalPlayer
function leftClick(player)
    TeleportService:Teleport("4291937431", player)

its supposed to teleport them to that id but it doesnt work!

it just says “invalid player”

1 Like

As you’re on the client I’m assuming as you’re using LocalPlayer, you don’t actually need to provide the player. Also, MouseButton1Click doesn’t return a player, so you’re getting nil, and trying to teleport nil. Also, I’m not sure if this is the problem or not, your placeid can be a number.

local TeleportService = game:GetService("TeleportService")

function leftClick()

1 Like

It is still sending me “Invalid player to teleport”

also i changed it to a string because i was just trying different things to see what was the problem

Is this in a local script? Can you send a picture of the error? Have you tried testing out of studio?

This is the exact message
17:49:08.691 - Invalid player to teleport.
it is attached to a button and i just used the normal script (idk what a local script is)
and no i havent tried that but i will

You must use a local script on gui buttons on the client side. LocalPlayer only works in LocalScript as well as teleporting without providing the player argument.


Thanks that worked