Unable to cast value to Object error

What do you want to achieve?
A working script/remote event where you can teleport to a player’s server

What is the issue?
I am getting a “Unable to cast value to object” error. https://cdn.discordapp.com/attachments/594659527316733973/859929201346871307/unknown.png

What solutions have you tried so far?
I have tried printing out a bunch of debug stuff to see if anything is nil, nothing is nil.

I will provide both the module function code and the code attached to the remote event I am trying to fire. I will attach a remote fire example too. How it works for the remote is your just entering a username in a textbox and then pressing a button to fire the remote.

Module code

function Handler:gotoServer(Admin, Username)

	local UserIdsuccess, userId = pcall(function() return game:GetService("Players"):GetUserIdFromNameAsync(Username); end);

	if (not UserIdsuccess) then
		warn(Username.. " not found on roblox.")
		return
	end
	
		local isInThisServer, error, placeID, jobID = TPS:GetPlayerPlaceInstanceAsync(userId)
		if not isInThisServer then
			warn("Teleporting...")
			warn(Admin)
			warn({Admin})
			warn(placeID)
			warn(jobID)
			TPS:TeleportToPlaceInstance(placeID, jobID, {Admin})
		elseif isInThisServer then
			warn("User is in your server")
			return
		end
	
	return true

end

RemoteEvent server code

local Remotes = game:GetService("ReplicatedStorage"):WaitForChild("Remotes")
local getServerRemote = Remotes:WaitForChild("getServer")
local Handler = require(game:GetService("ReplicatedStorage").AdminHandler)
local TPS = game:GetService("TeleportService")

function getServerInfo(_LocalPlayer, Username)
	
	if Username then
		Handler:gotoServer(_LocalPlayer, Username)
	end
	
end

getServerRemote.OnServerEvent:Connect(getServerInfo)

Remote example

local Remotes = game:GetService("ReplicatedStorage"):WaitForChild("Remotes")
local getServerRemote = Remotes:WaitForChild("getServer")

script.Parent.MouseButton1Click:Connect(function()
	warn(getServerRemote:FireServer(script.Parent.Parent.SearchBox.Text))
end)

Where did you got this error, localscript or server script

It’s on the server, in the module it looks like. Which line though?

Which lines is erroring, and in which script?

The module is erroring on this line

TPS:TeleportToPlaceInstance(placeID, jobID, {Admin})

The remote script is also erroring too but that’s because it’s calling the module function that creates an error.

The module is erroring on this line

TPS:TeleportToPlaceInstance(placeID, jobID, {Admin})

The remote script is also erroring too but that’s because it’s calling the module function that creates an error.

Through the module script on this line

TPS:TeleportToPlaceInstance(placeID, jobID, {Admin})

Try this one

TPS:TeleportToPlaceInstance(placeID, jobID, Admin)

The third parameter is not a table. It’s player object

1 Like

Lol worked, thanks. Idk why I had it as an array.

1 Like