Need Help With Teleporting Data

Hi! What I am trying to make is so when a player dies, they get teleported to another place and their data transfers with it. They end up teleporting but the data doesn’t transfer. Help would be greatly appreciated!

This is the code in place 1:

local player = game.Players.LocalPlayer
local char = player.Character
local humanoid = char:WaitForChild("Humanoid")

humanoid.Died:Connect(function()
	wait(2)
	print(char.Name)
	local placeId = 5821855946
	local tService = game:GetService("TeleportService")
	local player = game.Players.LocalPlayer
	if player then
		local data1 = {}
		data1["DeathFlowers"] = player.Character:WaitForChild("CoinsCollected").Value
		print(data1)
		tService:Teleport(placeId, player, data1)


	end

end)

This is the code in the place that they get teleported to this script is inside a gui in startergui:

image

local tService = game:GetService("TeleportService")

local data1 = tService:GetLocalPlayerTeleportData()

if data1 then
	local deathflowers = data1["DeathFlowers"]
	print(deathflowers)
	script.Parent.Text = deathflowers

else
	print("no data")
end

When you get teleported back the gui still says “Label”

Well, not gonna lie - never wondered about the teleport service abillities, but I think you can use BindableEvents to solve this. Create an remoteevent and fireclient once player dies to transfer data with it to 2nd localscript, finally - update information that you transfer using localscript.

I just think that possibly teleport service can’t transit data and as i understood from api, data is very strict to its type (as i understood it might don’t allow some of types of information) and if it’s true you can always transit data thru events. Hope I helped.

P.S.
Try to use event to fire the code like:

local tService = game:GetService("TeleportService")

anyevent.Event:Connect(function() --Any event that would start code
    local data1 = tService:GetLocalPlayerTeleportData()

    if data1 then
	    local deathflowers = data1["DeathFlowers"]
	    print(deathflowers)
	    script.Parent.Text = deathflowers

    else
	    print("no data")
    end
end

Maybe code is not running bcs of it just already done once at the moment of teleportation.

I am not really familiar with bindable events how would I use it in my script?

Sorry, I slept that time, so, sorry for late reply.

There are two similar events in Roblox Game Engine:
• BindableEvent ( Client → Client or Server → Server)
• RemoteEvent ( Client → Server or Server → 1 Client or Server → All Clients)

They are used usually to connect two scripts that should do something once event.

You can read API for these two events, but I’ll cover only BindableEvent now.
• You create an instance of event. BindabledEvents have to be placed in place where script can find it - For ex.: Don’t place event for LocalScript in ServerScriptStorage - LocalScript can
t see it on client bcs it’s only on server side.

• Make an origin script and fire event when it’s needed with all parameters.
• Make a destination script and start it with Event Listener that would make a code once event is being fired.

It looks like:
• Origin Script (X → …)

-- something
path_to_event:Fire(parameter_1,parameter_2, ... ,parameter_n)
-- something

• Destination Script (… → X)

path_to_event.Event:Connect(function(parameter_1,parameter_2, ... ,parameter_n)
    -- some stuff you do here
end)

RemoteEvent is kind of similar to this, but you have to read API bcs there are few differenses and it needs some additional parameters depends on how you use it.

1 Like

You can find more information, examples and some other stuff you might to need at these API pages.

When I work with teleport data, I use arrays since others have recommended that to me.


local data = {
   ["DeathFlowers"] = nil --// Your data you want to store here
}

And accessing it like this

print(data.DeathFlowers)
1 Like

Oh yeah I already figured it out on my own but thanks for your help though!