Expected identifier when parsing expression got ";"

Hi there. I just made a pretty simple script that teleports the local player to a different place within the experience. I know that this error means there’s something wrong with syntax, but I don’t see what I’m doing wrong. Script:

local button = script.Parent;
local players = game:GetService("Players");
local teleService = game:GetService("TeleportService");
local gameID = 10968441118;

button.MouseButton1Click:Connect(function()
	teleService:TeleportAsync(gameID, players.LocalPlayer);
end)

Help is appreciated!

Unlike some other languages, in Lua(u), you dont have to put that ; at the end of each line.

Do you have more code related to that?

local button = script.Parent
local players = game:GetService("Players")
local teleService = game:GetService("TeleportService")
local gameID = 10968441118

button.MouseButton1Click:Connect(function()
	pcall(function()
        teleService:TeleportAsync(gameID, players.LocalPlayer)
    end)
end)

I removed the ; and the error was still there

Is that a local script, right?

What line does it error on ? This would be very helpful.

1 Like

yes

char limit

sorry, it errors on line 4 when I look at the console

So, you removed all of the semi colons and the error was still there? That would make no sense. The script looks fine.

The TeleportAsync method needs two parameters: the location identifier for the teleport and a table containing the users you want to teleport.
https://developer.roblox.com/en-us/api-reference/function/TeleportService/TeleportAsync
Also, it can only be called on the server.

Change your script to this:

local button = script.Parent;
local players = game:GetService("Players");
local teleService = game:GetService("TeleportService");
local gameID = 10968441118;

button.MouseButton1Click:Connect(function()
	teleService:TeleportAsync(gameID, {players.LocalPlayer});
end)
1 Like

Yeah I removed all of them and it still doesn’t work

This still doesn’t work, does TeleportAysync need to be called from the server?

Yes, sorry I thought this was on the server for a second.

That might be the problem, this is on a local script. I might need to set up a remote event

You could just use Teleport

local button = script.Parent;
local players = game:GetService("Players");
local teleService = game:GetService("TeleportService");
local gameID = 10968441118;

button.MouseButton1Click:Connect(function()
	teleService:Teleport(gameID, players.LocalPlayer);
end)
1 Like

this worked! I think TeleportAsync can only be used server side

I am still confused on how you got the error “Expected identifier when parsing expression got “;” ", but I am glad it worked. :smiley:

1 Like

Based on the OP’s code and message, that error on line 4 would happen if they wrote something like this:

local gameID = ;

Running this in Luau’s demo (and I would assume studio) gives the same error:

Error:1: Expected identifier when parsing expression, got ‘;’

Maybe they forgot to commit a draft before testing?

He said he removed all the semi colons which is why I was confused, but maybe he didn’t commit it.

1 Like