What's wrong with my code that is causing Error Code 268?

My game is a game that sends people to random games, and I’ve been testing it. However, when I’m about to teleport, I get the error instead. I’ve tested it on my alt account and got the same issue. Though when I place another game similar to mine such as place roulette, I do not get the error. I’m wondering if this is an issue with my code or if it is an outside issue. Nevertheless, here is the code below:

local marketplaceService = game:GetService("MarketplaceService")
local tp = game:GetService("TeleportService")
local players = game:GetService("Players")
local part = script.Parent.Parent
local gameId = 0
local squad = {}
ready = false

local function addSquad(ppart)
	local name = game.Players:FindFirstChild(ppart.Parent.Name)
	if name then
		if table.find(squad, name) == nil then
			table.insert(squad, name)
		end
		for i, v in pairs(squad) do
			print(squad[i])
		end
	end
end

function IsGameValid(id)
	local isgame
	local success,message = pcall(function()
		local gameid = game:GetService('MarketplaceService'):GetProductInfo(id) 
		isgame = gameid.AssetTypeId == 9
	end)
	return success and isgame
end 

function teleport(ppart)
	if ready == false then
		script.Parent.Enabled = false
		for i, v in pairs(game.Players:GetChildren()) do
			v.PlayerGui.Countdown.Text.Text = "Searching for a game..."
		end
		while ready == false do
			local gameId = Random.new():NextInteger(3000, 12000000000)
			if IsGameValid(gameId) then
				local isSuccessful, info = pcall(marketplaceService.GetProductInfo, marketplaceService, gameId)
				if isSuccessful then
					if ready  == false then
						if info.Name:match("'s Place") or info.Name:match("#") then
							print("Insuffient detected")
						else
							script.PlaceName.Value = info.Name
							script.PlaceId.Value = gameId
							ready = true
						end
					end
				end
			end
		end
	end
	if ready then
		local timer = 5
		repeat
			for i, v in pairs(game.Players:GetChildren()) do
				if timer == 1 then
					v.PlayerGui.Countdown.Text.Text = "Teleporting to '" .. script.PlaceName.Value .. "' in 1 second..."
				else
					v.PlayerGui.Countdown.Text.Text = "Teleporting to '" .. script.PlaceName.Value .. "' in " .. timer .. " seconds..."
				end
			end
			wait(1)
			timer = timer - 1
		until timer < 0
		for i, v in pairs(squad) do
			if game.Players:FindFirstChild(v.Name) then
				local player = players:FindFirstChild(v.Name)
				tp:Teleport(script.PlaceId.Value, player)
				v:Destroy()
			end
		end
		squad = nil
		ready = false
		for i, v in pairs(game.Players:GetChildren()) do
			v.PlayerGui.Countdown.Text.Text = ""
		end
		script.Parent.Enabled = true
	end
end

script.Parent.Triggered:Connect(teleport)
part.Touched:Connect(addSquad)

maybe delete an extra 0 on your max integer, i think there’s only 10 digits or less in a game id although your code looks right, unsure

I deleted the extra 0 and unfortunately it’s still broken

Could you state the error in a clearer way if you can? Or is it really just error code 268.

I’ve done some testing and I’m not sure if it is a problem with the code since I forced the game iD to be one of my games, and the issue still persists. I’ve also got a friend to play the game and we both have been kicked for unexpected client behaviour.


It only shows this when it happens

I’m not really that experienced with teleport service so I suggest searching this error up for answers.

Edit: also is this script on the client or server-side? I see the error states “You have been kicked due to unexpected client behaviour.” Maybe try checking your client scripts to see if that’s the problem.

i looked it up apparently it means like, it thinks your cheating of some kind, not to accuse but i found an article saying it relates to DNS cache

1 Like

It’s a server-side script. Another thing is that the teleport used to work before I added the code to teleport players one by one. I’ll try to duplicate the code, and edit it so that it only teleports one player and see if it works, but I’ll have to do that in about 10 minutes since I’m going out. I hope that helps.

It may be because of too much pressure when teleporting all at once. That’s why I suggest checking any client-sided scripts you added in that other place.

1 Like

That could be the issue, error code 268 is a kick due to unexpected client behavior. It can be quite unexpected for every player in a server to be incrementally teleported to random places. Not sure though, I would recommend commenting out the teleport code and seeing if the issues persists. Also, does the user get teleported then kicked or just instantly kicked?

1 Like

I’ve only added server-side scripts into the game. It could be too much pressure but I’ve made it so that it teleports the players one by one every 5 seconds.

The player get’s kicked before being teleported

I edited the code so that it only teleports one player, and it works! I’ll post both scripts below and add comments.

Teleports multiple players script:

local marketplaceService = game:GetService("MarketplaceService")
local tp = game:GetService("TeleportService")
local players = game:GetService("Players")
local part = script.Parent.Parent
local gameId = 0
local squad = {} -- A table of all the players in the who are participating
ready = false

local function addSquad(ppart)
	local name = game.Players:FindFirstChild(ppart.Parent.Name) -- Finding the name of the player
	if name then -- If it can retreive the name then it'll do the code below
		if table.find(squad, name) == nil then -- Checks if the name already exists
			table.insert(squad, name) -- Adds the code into the squad
		end
		for i, v in pairs(squad) do
			print(squad[i])
		end
	end
end

function IsGameValid(id) -- Checks if the iD is a game iD
	local isgame
	local success,message = pcall(function()
		local gameid = game:GetService('MarketplaceService'):GetProductInfo(id) 
		isgame = gameid.AssetTypeId == 9
	end)
	return success and isgame
end 

function teleport(player)
	local attempt = 0 -- Stores how many attempts it takes to get an iD that has the right requirements
	part.Button:Play()
	if ready == false then -- Checks if a game has already been chosen
		script.Parent.Enabled = false -- Turns the prompt off
		for i, v in pairs(game.Players:GetChildren()) do -- Tells everyplayer the text below
			v.PlayerGui.Countdown.Text.Text = "Searching for a game (0 default places found)..." 
		end
		while ready == false do -- Checks if a game has already been chosen
			local gameId = Random.new():NextInteger(3000, 12000000000) -- Picks a random number
			if IsGameValid(gameId) then -- Checks if the iD is a game iD
				local isSuccessful, info = pcall(marketplaceService.GetProductInfo, marketplaceService, gameId)
				if isSuccessful then
					if ready  == false then
						if info.Name:match("'s Place") or info.Name:match("#") then -- Checks if the game is a default place
							print("Insuffient detected")
							attempt = attempt + 1
							print(attempt)
							if attempt == 1 then
								for i, v in pairs(game.Players:GetChildren()) do
									v.PlayerGui.Countdown.Text.Text = "Searching for a game (1 default place found)..." 
								end
							else
								for i, v in pairs(game.Players:GetChildren()) do
									v.PlayerGui.Countdown.Text.Text = "Searching for a game (" .. attempt .. " default places found)..." 
								end
							end
						else
							script.PlaceName.Value = info.Name -- Stores the info of the place name and iD
							script.PlaceId.Value = gameId
							ready = true -- Stops the game from finding a new game
						end
					end
				end
			end
		end
	end
	for i, v in pairs(game.Players:GetChildren()) do
		v.PlayerGui.Countdown.Text.Text = "Place found!" 
	end
	wait(1)
	if ready then
		local timer = 5
		repeat
			if timer == 1 then
				for i, v in pairs(game.Players:GetChildren()) do
					v.PlayerGui.Countdown.Text.Text = "Teleporting to '" .. script.PlaceName.Value .. "' in 1 second..."
				end
			else
				for i, v in pairs(game.Players:GetChildren()) do
					v.PlayerGui.Countdown.Text.Text = "Teleporting to '" .. script.PlaceName.Value .. "' in " .. timer .. " seconds..."
				end
			end
			script.Beep:Play()
			wait(1)
			timer = timer - 1
		until timer < 0
		game.Workspace.Closed.Transparency = 0
		game.Workspace.Closed.CanCollide = true
		script.Door:Play()
		script.Charge:Play()
		for i, v in pairs(squad) do -- Repeats the same amount of how many things that are in the squad
			if game.Players:FindFirstChild(v.Name) then -- Checks if the names that are in the squad are also in game
				local player = players:FindFirstChild(v.Name) -- Stores the name
				tp:Teleport(script.PlaceId.Value, player) -- Teleports the player to the game
				v:Destroy()
			end
			wait(5)
		end -- All the code below are effects
		wait()
		repeat
			wait(0.5)
		until game.Workspace.Glow.Light.Brightness == 10
		for i, v in pairs(squad) do
			table.remove(squad, i)
		end
		ready = false
		for i, v in pairs(game.Players:GetChildren()) do
			v.PlayerGui.Countdown.Text.Text = ""
		end
		script.Parent.Enabled = true
	end
end

script.Parent.Triggered:Connect(teleport)
part.Touched:Connect(addSquad)

Teleports only one player script:

local marketplaceService = game:GetService("MarketplaceService")
local tp = game:GetService("TeleportService")
local players = game:GetService("Players")
local part = script.Parent.Parent
local gameId = 0
local squad = {} -- A table of all the players in the who are participating
ready = false

local function addSquad(ppart)
	local name = game.Players:FindFirstChild(ppart.Parent.Name) -- Finding the name of the player
	if name then -- If it can retreive the name then it'll do the code below
		if table.find(squad, name) == nil then -- Checks if the name already exists
			table.insert(squad, name) -- Adds the code into the squad
		end
		for i, v in pairs(squad) do
			print(squad[i])
		end
	end
end

function IsGameValid(id) -- Checks if the iD is a game iD
	local isgame
	local success,message = pcall(function()
		local gameid = game:GetService('MarketplaceService'):GetProductInfo(id) 
		isgame = gameid.AssetTypeId == 9
	end)
	return success and isgame
end 

function teleport(player)
	local attempt = 0 -- Stores how many attempts it takes to get an iD that has the right requirements
	part.Button:Play()
	if ready == false then -- Checks if a game has already been chosen
		script.Parent.Enabled = false -- Turns the prompt off
		for i, v in pairs(game.Players:GetChildren()) do -- Tells everyplayer the text below
			v.PlayerGui.Countdown.Text.Text = "Searching for a game (0 default places found)..." 
		end
		while ready == false do -- Checks if a game has already been chosen
			local gameId = Random.new():NextInteger(3000, 12000000000) -- Picks a random number
			if IsGameValid(gameId) then -- Checks if the iD is a game iD
				local isSuccessful, info = pcall(marketplaceService.GetProductInfo, marketplaceService, gameId)
				if isSuccessful then
					if ready  == false then
						if info.Name:match("'s Place") or info.Name:match("#") then -- Checks if the game is a default place
							print("Insuffient detected")
							attempt = attempt + 1
							print(attempt)
							if attempt == 1 then
								for i, v in pairs(game.Players:GetChildren()) do
									v.PlayerGui.Countdown.Text.Text = "Searching for a game (1 default place found)..." 
								end
							else
								for i, v in pairs(game.Players:GetChildren()) do
									v.PlayerGui.Countdown.Text.Text = "Searching for a game (" .. attempt .. " default places found)..." 
								end
							end
						else
							script.PlaceName.Value = info.Name -- Stores the info of the place name and iD
							script.PlaceId.Value = gameId
							ready = true -- Stops the game from finding a new game
						end
					end
				end
			end
		end
	end
	for i, v in pairs(game.Players:GetChildren()) do
		v.PlayerGui.Countdown.Text.Text = "Place found!" 
	end
	wait(1)
	if ready then
		local timer = 5
		repeat
			if timer == 1 then
				for i, v in pairs(game.Players:GetChildren()) do
					v.PlayerGui.Countdown.Text.Text = "Teleporting to '" .. script.PlaceName.Value .. "' in 1 second..."
				end
			else
				for i, v in pairs(game.Players:GetChildren()) do
					v.PlayerGui.Countdown.Text.Text = "Teleporting to '" .. script.PlaceName.Value .. "' in " .. timer .. " seconds..."
				end
			end
			script.Beep:Play()
			wait(1)
			timer = timer - 1
		until timer < 0
		game.Workspace.Closed.Transparency = 0
		game.Workspace.Closed.CanCollide = true
		script.Door:Play()
		script.Charge:Play()
		tp:Teleport(script.PlaceId.Value, player)
		wait()
		repeat
			wait(0.5)
		until game.Workspace.Glow.Light.Brightness == 10
		for i, v in pairs(squad) do
			table.remove(squad, i)
		end
		ready = false
		for i, v in pairs(game.Players:GetChildren()) do
			v.PlayerGui.Countdown.Text.Text = ""
		end
		script.Parent.Enabled = true
	end
end

script.Parent.Triggered:Connect(teleport)
part.Touched:Connect(addSquad)

Edit: I tried editing the code so that it waits 5 seconds before teleporting players instead of teleporting players and then waiting 5 seconds but it doesn’t work, unfortunately. I’ll show you what the edited code looked like:

		for i, v in pairs(squad) do -- Repeats the same amount of how many things that are in the squad
			wait(5)
			if game.Players:FindFirstChild(v.Name) then -- Checks if the names that are in the squad are also in game
				local player = players:FindFirstChild(v.Name) -- Stores the name
				tp:Teleport(script.PlaceId.Value, player) -- Teleports the player to the game
				v:Destroy()
			end

I FINALLY GOT IT TO WORK!!! GUESS WHAT? IT WAS ONLY ONE LINE OF CODE.

v:Destroy()

This one line caused all the code to not work bruh. Anyways, I’d like to thank the people who replied for giving me advice on how to fix the code.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.