RemoteEvent arg returning nil

i have a remote event that sends the player’s item name that they had from the other server when they join

--Client
task.wait(3)

local rs= game:GetService("ReplicatedStorage")
local ts = game:GetService("TeleportService")
local td = ts:GetLocalPlayerTeleportData()
if td ~= nil then
	for i, v in pairs(td) do
		print(v)
		local obj = v
		game.ReplicatedStorage.Remotes.getData:FireServer(obj)
	end
end
--Server
game.ReplicatedStorage.Remotes.getData.OnServerEvent:Connect(function(plr, v)
	print("recieved")
	print(v)
	if game.Workspace:FindFirstChild(v) then
		local Item = workspace[v]:Clone()
		Item.Parent = plr.Backpack
	end
end)

on the client it prints “AlmondWater” if they had that in the other place before getting teleported to this place
on the server it prints “received” and “nil”
but they had almond water not nil
whats going on
im getting so tired of getting nil-related errors

The TeleportData is local to the client, so while the client can use it, the server has no access and from the server’s view it doesn’t exist which is why it is printing nil. Additionally, TeleportData is not secure and should not be used for sending sensitive data because exploiters can intercept and modify it. A more secure and server-sided solution is to send the data using MemoryStoreService.

2 Likes

well can you say how? (that wasnt intended to be rude)

1 Like

Save data from the previous server:

MemoryStoreService:GetQueue(--[[Player's UserId]], 120):AddAsync(--[[Data you are sending (can be anything)]], 120)

Retrieve data from teleported-to server:

MemoryStoreService:GetQueue(--[[Player's UserId]], 120):ReadAsync(1)[1]

and should i put these in workspace or something

This is intended to be used in a server-side script. As long as the scripts can run in that container, it can be anywhere.

well one more thing, is it activated when the player teleports? i have never seen MemoryStoreService before so idk what this is

MemoryStoreService allows you to save data for a set period of time (in this scenario, 120 seconds to allow enough time for teleports). This data will be available until it expires. So, whenever you teleport a player, send their data using MemoryStoreService and when they arrive at their destination (I would recommend using something like Players.PlayerAdded), you can retrieve their data since you will have their ID.

okay but do i addasync when the player teleports and readasync when the Player (is) Added?

Use AddAsync when you teleport the player and ReadAsync when you are getting their data in the server you teleport them to.

i get their data in a local script like the thing above but you said it was serversided

MemoryStoreService is server-sided which actually makes your life easier since you won’t need to use any RemoteEvents since it will already be on the server.

1 Like

so i literally just put this into the server script then im done?

You’ll need to put the player’s UserId and send the data from the previous server but other than that you shouldn’t have to do anything else.

local mss = game:GetService(“MemoryStoreService”)

i put

mss:GetQueue(--[[Player's UserId]], 120):ReadAsync(1)[1]

into the get data server script and it said “expect assignment or function call”, so what??

nvm im just incredibly dumb fnkjfiskdfjsldkfjsdf

@wwwaylon09_backup i tried this

local ts = game:GetService("TeleportService")
local mss = game:GetService("MemoryStoreService")
local db = true

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

			mss:GetQueue(player.UserId, 30):AddAsync(inv, 30)
			ts:Teleport(14580857434, player, inv)

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

script.Parent.Touched:Connect(touched)

i got this error

invalidrequest: unable to convert value to JSON. API: Queue.add, data structure: 1613443759

aka my user id

The queue name needs to be a string so just use tostring():

mss:GetQueue(tostring(player.UserId), 30):AddAsync(inv, 30)

i got the same error (this character limit is annoying me)

Looks like you can’t send Instances through MemoryStoreService because it gets encoded in JSON. If you have the items in the place you teleport the player to, you can send their names in a table then give them items based on the names in the table.