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)