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)
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.
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
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 …
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.