Argument 1 missing or nil

I am a developer, working on games that are very peculiar. I stumbled across this problem using TeleportAsync and it returns this: Argument 1 missing or nil. If anybody could help me with this issue, as I looked for solutions on other posts and I could not clearly understand what was going on.

Scripts down below

Client

local plr = game.Players.LocalPlayer
local pages = game:GetService("AssetService"):GetGamePlacesAsync()
local TeleportService = game:GetService("TeleportService")
local codeTable = string.split(script.Parent.Parent.code.Value,",")

local function ButtonClicked()
	if table.find(codeTable, script.Parent.Parent.EnterCode.Text) then
		while true do
			print("Works 1")
			for _,place in pairs(pages:GetCurrentPage()) do
				print("Works 2")
				print(place)
				if script.Parent.Parent.EnterCode.Text == tostring(place.Name) then
					print("Works 3")
					game.ReplicatedStorage.plrName.Value = plr.Name -- original plr.Name
					game.ReplicatedStorage.isFired.Value = true
					game.ReplicatedStorage.placeID.Value = tostring(place.PlaceId)
					-- TeleportService:TeleportAsync(place.PlaceId,{plr})
					print("Works 3.1")
				end
			end
			if pages.IsFinished then 
				break
			end
			pages:AdvanceToNextPageAsync()
		end
	else
		print("Code invalid.",codeTable)
	end
end


script.Parent.Parent.Button.MouseButton1Click:Connect(ButtonClicked)



Server

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TeleportService = game:GetService("TeleportService")

while wait(0.5) do
	if ReplicatedStorage.isFired == false then

	else
		local plrName = ReplicatedStorage.plrName
		local placeID = ReplicatedStorage:WaitForChild("placeID")
		local plr = Players:FindFirstChild(plrName.Value)
		TeleportService:TeleportAsync(tonumber(placeID.Value),{plr})
		wait(2)
		ReplicatedStorage.isFired.Value = false
		ReplicatedStorage.placeID.Value = ""
		plrName.Value = ""
	end

end

Thanks again for helping!

since tonumber() returns nil when it is used on something that isn’t a number, placeID.Value probably isn’t a number. Perhaps print placeID.Value right before you run the teleport.

But then it just returns “Unable to cast string to int64”?

I’m pretty sure you only get “Unable to cast string to int64” when you try to set the value of an intvalue to a string. What line is causing it?

I set the placeID value to an int, but it still says “Unable to cast string to int64”

This line is causing it: ReplicatedStorage.placeID.Value = “”

No, but I changed the values into tonumber()

so you removed the line that sets the placeID value to a string and you’re still having the error?

Yeah? It’s pretty weird as I had this for a long time and nobody could solve it. I can possibly give you the updated code and see what’s wrong?

If you send the code ill try to run it in studio and fix it.

Client

local plr = game.Players.LocalPlayer
local pages = game:GetService("AssetService"):GetGamePlacesAsync()
local TeleportService = game:GetService("TeleportService")
local codeTable = string.split(script.Parent.Parent.code.Value,",")

local function ButtonClicked()
	if table.find(codeTable, script.Parent.Parent.EnterCode.Text) then
		while true do
			print("Works 1")
			for _,place in pairs(pages:GetCurrentPage()) do
				print("Works 2")
				print(place)
				if script.Parent.Parent.EnterCode.Text == tostring(place.Name) then
					print("Works 3")
					game.ReplicatedStorage.plrName.Value = plr.Name -- original plr.Name
					game.ReplicatedStorage.isFired.Value = true
					game.ReplicatedStorage.placeID.Value = tonumber(place.PlaceId)
					-- TeleportService:TeleportAsync(place.PlaceId,{plr})
					print("Works 3.1")
				end
			end
			if pages.IsFinished then 
				break
			end
			pages:AdvanceToNextPageAsync()
		end
	else
		print("Code invalid.",codeTable)
	end
end


script.Parent.Parent.Button.MouseButton1Click:Connect(ButtonClicked)

Server

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TeleportService = game:GetService("TeleportService")

while wait(0.5) do
	if ReplicatedStorage.isFired == false then

	else
		local plrName = ReplicatedStorage.plrName
		local placeID = ReplicatedStorage:WaitForChild("placeID")
		local plr = Players:FindFirstChild(plrName.Value)
		TeleportService:TeleportAsync(placeID.Value,{plr})
		wait(2)
		ReplicatedStorage.isFired.Value = false
		ReplicatedStorage.placeID.Value = 0
		plrName.Value = ""
	end
end

I’ll be AFK for the time being, but if you fixed it please let me know!

The way I also made it was inputting text into a button

So there are many problems with your scripts. Right off the bat I notice that you are changing values in replicated storage on the client. Since FilteringEnabled has become a thing, if you change something with a localscript only the client will see the change, the server and other players will be left uninfected. A simple solution would be to fire a remote event will the 1st parameter being the code that the player put in, and have the server do all the checks about whether to teleport or not.

the way u are firing the event just doesnt make sense to me. it seems the problem is you are setting a value in replicated storage to true on the client side, the two problems with the code:

  • the server cant see any changes the client makes in the game explorer (this includes replicated storage)
  • when the server is checking if the event is fired its not even checking the value it should be:

server side:

if game.ReplicatedStorage.isFired.Value == false then

so my suggestion is go learn how to use remote events:

It still returns the same error message, even with the remote event.

It still returns the same error message, even with the remote event

I have made some example code for your:

Client

local event = game:GetService("ReplicatedStorage").RequestTeleport

script.Parent.TeleportButton.MouseButton1Click:Connect(function()
	event:FireServer(script.Parent.CodeBox.Text)
end)

Server

local event = game:GetService("ReplicatedStorage").RequestTeleport
local TeleportService = game:GetService("TeleportService")

local place = game.PlaceId

event.OnServerEvent:Connect(function(plr, codeText)
	-- run checks to see if its a valid code
	TeleportService:TeleportAsync(place,{plr})
end)

Super close, but now it returns “Unable to cast value to Object”

which line in which script gives this error?

Serversided script. ……… (filler)