TeleportData not working!

I’m making a story game, but there is one bug that occurs. There’s a script where I want players to teleport to another place and the player’s health + tools will be carried to the new place when they teleport.

For example, I want to teleport Player1 from “Main Place” to “Ending Place” but the health that the Player1 had in Main Place will be remained same when he joins the Ending Place.

Here is the teleport Server Script (in the Main Place):

game.ReplicatedStorage.TeleportTime:FireAllClients()
for _, player in pairs(game.Players:GetPlayers()) do
	local teleportData = {
		health = player.Character.Humanoid.Health,
		tools = {}
	}
	for _, tool in pairs(player.Backpack:GetChildren()) do
		table.insert(teleportData.tools,tool.Name)
	end
	for _, tool in pairs(player.Character:GetChildren()) do
		if tool:IsA('Tool') then
			table.insert(teleportData.tools,tool.Name)
		end
	end
	teleportData = game.HttpService:JSONEncode(teleportData)
	teleportService:TeleportToPrivateServer(5844872161, code, {player}, teleportData)
end

Here is the LocalScript in StarterPlayerScripts (in the Ending Place)

local player = game:GetService('Players').LocalPlayer
local teleportService = game:GetService('TeleportService')
local teleportData = teleportService:GetLocalPlayerTeleportData()


if teleportData then
	teleportData = game.HttpService:JSONDecode(teleportData)
	print('Teleport Data found!')
	game.ReplicatedStorage.TeleportData:FireServer(teleportData)
else
	print('No teleport data')
end

It just prints ‘No teleport data’

First we thought that JSONEncode / JSONDecode might be the problem but when we removed it, it prints an error in the output saying "Unable to cast value to std::string"
error

Any idea what to do? Any help would be appreciated!

6 Likes

It should be in ReplicatedFirst

I don’t think that will affect anything. I had one for my old game museum that I had and that was in StarterGui. I wrote Menace’s in StarterPlayerScripts, which shouldn’t affect anything.

I believe you are deciding the data, but you didn’t encode it in the first place. Try deleting the JSONDecode and pass the table through instead.

1 Like

Sometimes locations randomly help :thinking:

Why did you delete this post? Did it work? If not tell me so I can look more closely at what the issue is.

1 Like

No it’s still not working out…

I think you’re missing a parameter here:

There is a parameter called “SpawnName” before the teleport data, try setting it to nil:

teleportService:TeleportToPrivateServer(5844872161, code, {player},nil, teleportData)

1 Like