Memory store only work once?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Getting player’s position from another server

  2. What is the issue? It only works once, After I press spectate once, Itll generate saved position of the player, But if I click spectate again,But with different player for playtesting, It did not generate my alt’s position, Single player re spectation work (Spectating same player after some amount of time
    Saving code:

local MemoryStoreService = game:GetService("MemoryStoreService")

local sortedMap = MemoryStoreService:GetSortedMap("SortedMap1")

local i = 0
local StoredField = {}
local finalField = {}

local pushLimit = 1600
local pushTimer = 3 
local Frequency = 0.25


while true do
	task.wait(Frequency)
	i = i + 1
	for _, v in pairs(game.Players:GetChildren()) do
		if v.Character  then
			StoredField[i] = {}
			StoredField[i][tostring(v.UserId)] = {math.round(v.Character.PrimaryPart.Position.X),math.round(v.Character.PrimaryPart.Position.Y),math.round(v.Character.PrimaryPart.Position.Z)}
		end
	end
	if string.len( game.HttpService:JSONEncode(StoredField)) >= pushLimit then
		i = 0
		StoredField = {}
		--print("SETTED "..game.HttpService:JSONEncode(StoredField))
		sortedMap:SetAsync(game.JobId,finalField,100)
	else
		print( string.len( game.HttpService:JSONEncode(StoredField)))
		finalField = StoredField
	end
	
end

Getting code


local MemoryStoreService = game:GetService("MemoryStoreService")

local sortedMap = MemoryStoreService:GetSortedMap("SortedMap1")

script.Parent.RemoteEvent.OnServerEvent:Connect(function(plr,Username)
	if game["Teleport Service"]:GetPlayerPlaceInstanceAsync(game.Players:GetUserIdFromNameAsync(Username)) then
		local id = game.Players:GetUserIdFromNameAsync(Username)
		local getSuccess, items = pcall(function()
			local currentInstance, _, placeId, jobId = game["Teleport Service"]:GetPlayerPlaceInstanceAsync(id)
			--print(jobId)
			--print(sortedMap:GetAsync(jobId))
			return sortedMap:GetAsync(jobId)
		end)
		if not getSuccess then
			 warn(items)
		else
			for _,v in pairs(items) do
				if v then
					if not v[tostring(game.Players:GetUserIdFromNameAsync(Username))] then continue end
					local dummy = script.Dummy:Clone()
					dummy.Parent = workspace
					local desc = game.Players:GetHumanoidDescriptionFromUserId(id)
					dummy.Humanoid:ApplyDescription(desc)
					dummy.HumanoidRootPart.Anchored = true
					dummy:SetPrimaryPartCFrame(CFrame.new( Vector3.new( v[tostring(id)][1], v[tostring(id)][2], v[tostring(id)][3])))
				end
			end
		end
	end
end)

You need to save the data with the Player.UserId to get the player’s data.

So, I need to save player’s position independently?Every 0.25 second? You see, I saved instead of per player, I save per server, With each player being in a table which is created every 0.25 second, And I could actually read values from the table, BUT, Some time, This does not work. Like it could only track one player, And could have only been spectated by 1 player, When infact, The information is correct