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
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.
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
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:
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)