Unable to cast Value to Objects - TeleportService

I’ve been having this problem, with server joinings on my game. I’ve tried both {player} and player at line 22, so I don’t know what else causes the problem, can someone help me.

local MeetingDataStore = game:GetService("DataStoreService"):GetDataStore("MeetingDataStore")
local TeleportService = game:GetService("TeleportService")

game.ReplicatedStorage.VerifyKeys.OnServerEvent:Connect(function(player,MeetingId,password)
	local meeting = string.lower(MeetingId)
	
	local plridkey = meeting.."-CreatorID"
	local serveridkey = meeting.."-ServerID"
	local pass = meeting.."-Password"
	
	local UserId
	local ServerId
	local Password
	pcall(function()
		UserId = MeetingDataStore:GetAsync(plridkey)
		ServerId = MeetingDataStore:GetAsync(serveridkey)
		Password = MeetingDataStore:GetAsync(pass)
	end)
	
	if UserId ~= nil then
		if password == Password then
			TeleportService:TeleportToPrivateServer(6519214595,ServerId,{player})
		else
			game.ReplicatedStorage.VerifyKeys:FireClient(player,"invalid")
		end
	else
		game.ReplicatedStorage.VerifyKeys:FireClient(player,"invalid")
	end
end)
1 Like

You actually have to use ReserveServer and use the code for the server Roblox gives you. You can’t make your own key.

1 Like

There is another script handling the ReserveServer, that code is stored in the DataStore and assigned to a simplified code, that teleports you there.

You’re firing to the server correctly, right?

Can we see the client script that sends the event?

Sure!

script.Parent.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.VerifyKeys:FireServer(script.Parent.Parent.MeetingId.Text, script.Parent.Parent.Password.Text)
	script.Parent.Text = "Joining..."
	script.Disabled = true
end)

I can see it say “Joining…”, but it errors. It suposed to say Failed, if the password or meet id don’t match.

game.ReplicatedStorage.VerifyKeys.OnClientEvent:Connect(function(args)
	if args == "invalid" then
		script.Parent.Text = "Failed"
		wait(2)
		script.Parent.Text = "Join"
		script.Parent.LocalScript.Disabled = false
	end
end)

Strange, nothing I can see that’s wrong with the codes

Here’s the code that handles the ReserveServer in case you can see something wrong.

local MeetingDataStore = game:GetService("DataStoreService"):GetDataStore("MeetingDataStore")
local TeleportService = game:GetService("TeleportService")

function generateRandomString()
	local StringTable = {"q","w","e","r","t","y","u","i","o","p","a","s","d","f","g","h","j","k","l","z","x","c","v","b","n","m","1","2","3","4","5","6","7","8","9","0","-"}
	
	local MeetingId = ""
	
	for i = 1,15,1 do
		local random = Random.new()
		local chosenString = StringTable[random:NextInteger(1,#StringTable)]
		MeetingId = MeetingId..chosenString
		
	end
	
	return MeetingId
end

game.ReplicatedStorage.Create.OnServerEvent:Connect(function(player,password)
	print("started")
	
	local MeetingId = generateRandomString()
	while MeetingDataStore:GetAsync(MeetingId.."-CreatorID") ~= nil do
		MeetingId = generateRandomString()
		wait()
	end
	print(MeetingId)
	if player then
		local ServerId = TeleportService:ReserveServer(6519214595)
		player.Teleporting.Value = true
		MeetingDataStore:SetAsync(MeetingId.."-CreatorID",player.UserId)
		MeetingDataStore:SetAsync(MeetingId.."-ServerID",ServerId)
		MeetingDataStore:SetAsync(MeetingId.."-Password",password)
		MeetingDataStore:SetAsync(player.UserId.."-MeetingID",MeetingId)
		print("finished")
		print("teleporting")
		player.Teleporting.Value = false
		TeleportService:TeleportToPrivateServer(6519214595,ServerId,{player})
	end	
end)

You tried this in-game right? Because I still can’t see anything wrong with it. Someone else might though

Wait no, I think I figured it out:

local AccessCode, ServerId = TeleportService:ReserveServer(6519214595) -- try this

Yeah I tried in game, let me try your other solution.

Nope, still getting the error. I don’t know what to do at this point.
Second weird thing, the error only happens when joining, not when creating. The creator teleports just fine.

Is the issue resolved yet? If not, I could try to help as well

When you say only happens when joining, do you mean when the person gets teleported to that place and then the error appears when they join the place they were teleported to?

I meant that the first person creates the server and teleports just fine. But when that person gives the ID and the password for the second person to teleport, it errors.

Which code handles the password nandling and teleportation again?

The very first one, at the top of the thread

It could be something wrong with the player instance given from onServerEvent. Or wait hang on, it could be something with the names of the Remotes? Since one for FireServer and one for FireClient both use the same name, I’m not sure if it would work but maybe you could rename one of them?

Still getting an error, but is specifies the line that teleports the second player.
It’s just a console error. Not a on-screen “Unabled to teleport”.

1 Like

Try seeing what happens when you print player, if you’re getting that error it must mean you’re trying to teleport something else other than a player, so something is going on with that parameter

Edit
: For taht error, were you testing it in studio?

I’m not testing in studio. And printing the player prints my username.

Okay so it has to be something wrong with the ServerID since the place id looks the same and the player is obviously going to work since it no longer errors about casting value to objects.

Can you try checking if they’re both the same when you retrieve them via a print in the event where you create a meeting and in the first code after getting the ServerId from the datastore