Unable to cast value to Objects

Hi!

This is my teleport script.

game.Workspace.Elevator1aTPPart.Touched:Connect(function(a)
	local partParent = a.Parent
	local humanoid = a.Parent:FindFirstChildWhichIsA("Humanoid")
	print("Touched")
	if humanoid then
		local player = game.Players:GetPlayerFromCharacter(a.Parent)
		game:GetService("TeleportService"):TeleportAsync(tonumber(script.Parent:GetAttribute("ID")), player)
	end
end)

The issue is, when I try to teleport, I get this error.
image
I think the issue may be in the attribute, but it’s a number.
Thanks for any help!

TeleportAsync’s 2nd parameter takes an array of players, not a single value. If you’re wanting to just teleport one player, put it inside an array ({player}).

game:GetService("TeleportService"):TeleportAsync(tonumber(script.Parent:GetAttribute("ID")), {player})
3 Likes