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)
end
script.Parent.MouseButton1Click:Connect(leftClick)
its supposed to teleport them to that id but it doesnt work!
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()
TeleportService:Teleport(4291937431)
end
script.Parent.MouseButton1Click:Connect(leftClick)
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.