Bringing Over Items and Values When Teleporting to a Different Place

In my backrooms game, I have an InventorySlots value and some Almond Water that the player might have when teleporting through levels. Can someone tell me how to bring their tools over to the place they teleport to?

Here’s my script:

local TeleportService = game:GetService("TeleportService")

function touched(part)
	local char = part.Parent
	local player = game.Players:GetPlayerFromCharacter(char)

	TeleportService:Teleport(14537311013, player)
end

script.Parent.Touched:Connect(touched)
3 Likes

You can use SetTeleportSetting to set the teleport settings of what tools they equip.

I’m completely new to TeleportService, so I don’t exactly know what that is

…I’d really like for some one to answer

This is missing a lot you’ll have to add but, it shows a way. Sorry, these scripts in my code are huge doing many things. These are just snips out of them set up like an example. You’ll have to tailor this to your needs.

-- non-local script in ported from game
local data = {}; data["Stuff"] = 12345
local ts = game:GetService("TeleportService")
ts:Teleport(placeId, player, data)

-- local script in ported to game
local ts = game:GetService("TeleportService")
local td = ts:GetLocalPlayerTeleportData()
if td ~= nil then
	if td["Stuff"] == 12345 then
           -- they have stuff  
	end
end

I’d suggest just sending a code like this one. Then having your other program figure out what they get based off that code. Because this overall is not secure. So sending over a huge list will end up getting hacked. But you could send over a whole table if you liked. This probably will get hacked either way.

I use this to tell the game what placeID they came from, so it knows where to port them back.

local script would go into StarterPlayerScripts, right?

For me the FROM script is in ServerScriptService and the TO script is in StarterGui.
And the script you posted back is a non-local script, the other is local.

Kind of (poorly) just showing you the optional option to the Teleport command.
It can also send string data … even tables.

I tried this but it didn’t work. am i doing something wrong?

--Non-Local Script
local TeleportService = game:GetService("TeleportService")



function touched(part)
	local char = part.Parent
	local player = game.Players:GetPlayerFromCharacter(char)
	local inv = game:GetService("Players"):GetPlayerFromCharacter(part.Parent).Backpack:GetChildren()
	
	local ts = game:GetService("TeleportService")
	ts:Teleport(14580857434, player, inv)
end

script.Parent.Touched:Connect(touched)

--Local Script
local ts = game:GetService("TeleportService")
local td = ts:GetLocalPlayerTeleportData()
if td ~= nil then
	for i, v in pairs(td) do
		if game.Workspace:FindFirstChild(v.Name) then
			local Item = game.Workspace[v.Name]:Clone()
			Item.Parent = game.Players.LocalPlayer.Backpack
		end
	end
end

are u there? (character limit)

This part isn’t going to work …
inv = game:GetService(“Players”):GetPlayerFromCharacter(part.Parent).Backpack:GetChildren()

It has to be A string or a table.

:GetChildren() is a table lol (c lim)

also the error is attempt to index nil with “backpack”

Non-Local Script (Teleport From Program):

local ts = game:GetService("TeleportService")

function touched(part)
    local char = part.Parent
    local player = game.Players:GetPlayerFromCharacter(char)
    local inv = game:GetService("Players"):GetPlayerFromCharacter(char).Backpack:GetChildren()

    ts:Teleport(14580857434, player, inv)
end
script.Parent.Touched:Connect(touched)

Local Script (Teleport To Program):

task.wait(3)
local ts = game:GetService("TeleportService")
local td = ts:GetLocalPlayerTeleportData()
if td ~= nil then
    for i, v in pairs(td) do
        if game.Workspace:FindFirstChild(v.Name) then
            local Item = game.Workspace[v.Name]:Clone()
            Item.Parent = game.Players.LocalPlayer.Backpack
        end
    end
end

I think I just did the same two scripts you did …
Mind you I’m not testing anything as I go here.
So you need to make sure it can even find the backpack
Maybe try a wait on top to give things time to load …

im starting to think roblox studio isnt working, ive gotten 3 different attempt to index nil with whatevers today

It’s never Roblox, even though sometimes I wish it was …
Have to go line by line and make sure everything is working.
Use prints

well, i can still teleport, which means the backpack part probably isnt anything important. but my stuff doesnt carry over.

print the table after you create it … is that part working.
How many possible items are you talking here?

It prints all their items, and maybe like… 2

Got it to print the items in the back pack

task.wait(3)
local ts = game:GetService("TeleportService")
local db = true

function touched(part)
	if db then db = false
		local character = part.Parent
		local player = game.Players:GetPlayerFromCharacter(character)
		if player then
			local inv = player.Backpack:GetChildren()

			print(inv)

		end
		task.wait(3)
		db = true
	end
end

script.Parent.Touched:Connect(touched)

that old script fires off anything it touches, that needs to make sure it’s a player.
It is making a table. so sweet … now we need to read that from the other script.

no need to make that, its working now :+1: thanks