Unable to cast value to std::string

Hello, I wrote the following script:

local teleportService = game:GetService('TeleportService')
local code = teleportService:ReserveServer(5844872161)
game.ReplicatedStorage.TeleportTime:FireAllClients()
for _, player in pairs(game.Players:GetPlayers()) do
	spawn(function()
		local teleportData = {
			['health'] = player.Character.Humanoid.Health,
		}
		teleportService:TeleportToPrivateServer(5844872161,code,player,teleportData)
	end)

end

I’m getting this error:
image
Thank you for help!

2 Likes

Fixed my problem by doing:

for _, player in pairs(game.Players:GetPlayers()) do
	spawn(function()
		local teleportData = {
			['health'] = player.Character.Humanoid.Health,
		}
		teleportData = game.HttpService:JSONEncode(teleportData)
		teleportService:TeleportToPrivateServer(5844872161,code,{player},teleportData)
	end)

end

1 Like