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"
Any idea what to do? Any help would be appreciated!