Teleport script broken

What I want to achieve: Teleporting players

  1. The issue: On the teleport result specifically on the second argument on teleport async I tried countless times to get the player but I couldn’t.

  2. I’ve tried to change it to the humanoid and getting the children of game.Players and as well as using
    game.Players:GetPlayers() but only one thing works which is that I need to say specifically who is getting teleported for instance this would work: game.Players.wesam1992 and I’d get teleported but only those who I put their names in the script and the script would teleport them

It is a Server-side script.

	local players = game:GetService("Players")
					local DataStoreService = game:GetService("DataStoreService")
					local TeleportService = game:GetService("TeleportService")
					local ServerAccessCodes = DataStoreService:GetDataStore("ReservedServerAccessCodes")

					


					local teleportOptions = Instance.new("TeleportOptions")
			
					teleportOptions.ShouldReserveServer = true
	
				game.Players.PlayerAdded:Connect(function(Player)
		
				                                                               	-- problem ⬇
					local teleportResult = TeleportService:TeleportAsync(8117862651, {Player.Name}, teleportOptions)
		                                                  
					ServerAccessCodes:SetAsync(teleportResult.PrivateServerId, teleportResult.ReservedServerAccessCode)
				
					local accssCode = game.PrivateServerId ~= "" and ServerAccessCodes:GetAsync(game.PrivateServerId)
					print ("tp ran")

(Thanks for reading!)

1 Like

Why are you doing getting the player’s name here? It should be the player, not their name.

So, it should be

local teleportResult = TeleportService:TeleportAsync(8117862651, {Player}, teleportOptions)
1 Like

Well I was just desperate for any solutions that’s why I was trying the player’s name
Anyways I’ve tried your fix but It doesn’t seem to be working.

Are there any errors when you try out putting the player instead of the player’s name?

Edit: I’m 100% sure that it’ll be the player (instance) because the forum has the script with the player instance in it.

1 Like

Well, but What are they referencing the player as? Local player or a function etc? I tried to print the Player to see what it would give but It wasn’t printing it meaning that there is an error in the code itself. I’ll go debug it and come back.

1 Like

I tried helping and I put the script in StarterPlayer > StarterPlayerScripts

local players = game:GetService(“Players”)

local DataStoreService = game:GetService(“DataStoreService”)

local TeleportService = game:GetService(“TeleportService”)

local ServerAccessCodes = DataStoreService:GetDataStore(“ReservedServerAccessCodes”)

local teleportOptions = Instance.new(“TeleportOptions”)

teleportOptions.ShouldReserveServer = true

game.Players.PlayerAdded:Connect(function(player)

local teleportResult = TeleportService:TeleportAsync(8117862651,{player}, teleportOptions)

ServerAccessCodes:SetAsync(teleportResult.PrivateServerId, teleportResult.ReservedServerAccessCode)

local accssCode = game.PrivateServerId ~= “” and ServerAccessCodes:GetAsync(game.PrivateServerId)

print(“TP RAN”)

end)

No errors pop up and I don’t know if its working…

1 Like

I’ll check if this would work or not (thanks for the helping at least even if it didn’t work)

1 Like

If you want other people to help you should put tag like “Scripting”, “Bugs” “Help”, etc so it gets more out there.

1 Like

I tried what you said and it says unable to cast value to object

1 Like

I tried removing the function since it didn’t run after that function and so it only said Invalid list of players for teleport

teleportresult fdgfdggggggdfgfdgkdfjgoidfjgoidf

1 Like

i made a local variable for it and put it there but the error is the player

1 Like

the output says 8117862651 ForgetableLife Instance

1 Like

but the script is saying the you cant cast a value on a object

1 Like

I’ll try it and tell you the results.

I have the script in serverscriptservice

1 Like

The script doesn’t even print “TP RAN” meaning that there is an error

local DataStoreService = game:GetService(“DataStoreService”)
local TeleportService = game:GetService(“TeleportService”)
local ServerAccessCodes = DataStoreService:GetDataStore(“ReservedServerAccessCodes”)
local teleportOptions = Instance.new(“TeleportOptions”)
local PlaceId = “8117862651”

teleportOptions.ShouldReserveServer = true

game.Players.PlayerAdded:Connect(function(Player)

print(PlaceId,Player,teleportOptions)

local teleportResult = TeleportService:TeleportAsync(PlaceId, Player.Name, teleportOptions)

ServerAccessCodes:SetAsync(teleportResult.PrivateServerId, teleportResult.ReservedServerAccessCode)

local accssCode = game.PrivateServerId ~= “” and ServerAccessCodes:GetAsync(game.PrivateServerId)
print (“tp ran”)
end)

1 Like

Same thing here and it is on the teleportasync line

wait forgot that i had it as player.name says the same thing though

1 Like