Send data when a player teleports back to lobby

I have a system which puts players in a lobby and teleports them to a reserved server, when a player wins the game or dies it has the option to teleport back to lobby. What I want to do is be able to send the money data and check if they won when they tp to the lobby so it adds it to their leaderstat (profilestore.)

Making it save when they win, not when they teleport to lobby would be ideal but idk how I’d save the data in the lobby game with profileService if the player isn’t in the lobby so doing it when the plr teleports to lobby works too

1 Like

you also read and save player data in your reserved place
so they are already saved when they leave reserved place

?? What I’m saying is the reserved server is in a separate sub place than the lobby

Yeah, he’s saying that datastores work in reserved servers as they do in regular servers. I’m not too sure about this so do an experiment where you write data to a datastore via SetAsync() in the private server, then try to do GetAsync() in the regular server. You can just use the command bar for this.

Yeah I found that out, but when I use :GetAsync I get this error: 22:10:57.921 ReplicatedStorage.Services.ProfileStore:390: attempt to concatenate nil with string - Server - ProfileStore:390

This is my testing code currently, I followed the documentation so I’m unsure why the error is appearing.

local escape = {}

local ProfileStore = require(game.ReplicatedStorage.Services.ProfileStore)

function escape.EscapePlayer(plr)
	if plr then
		local money = plr:GetAttribute("Money")
		if money then
			print("DATA_"..tostring(plr.UserId))
			local data = ProfileStore:GetAsync("DATA_"..tostring(plr.UserId))
			print(data)
		end
	end
end

return escape

Print out plr and money to see if they’re nil.

use the same logic as your main place to use the ProfileStore
do all the reconcile, etc. not just GetAsync
you can copy and place your script from main place into the subplace to maintain the same data loading saving logic

I read the documentation and what I’m currently doing, is in the subplace I’m going to GetAsync to get the data from the lobby and overwrite it using SetAsync when they escape. The problem I’m having is this error, which I’m unsure why it’s popping up because the string is not nil, and I’m 99% data saves across sub places.

did you also use GetAsync and SetAsync in your main place? you should not
also because you won’t exist in lobby and reserved place at the same time,

example you should use : Basic Usage
https://madstudioroblox.github.io/ProfileStore/tutorial/

you should not use GetAsync and SetAsync
they are for situations where you are certain a player do not exist in any server, but you want to read and modify their data. such as if you somehow want to modify a certain data of a player on the leaderboard because you think he is cheating and you want to make things right.

from your use case, your player is playing actively on the reserved server, so you should load and save their data like in the Basic usage

The data is loading and saving in the lobby, and they’re not in the lobby meaning they don’t have a current active session. Which is why I’m using Get and SetAsync (in the subplace)

also improper use of ProfileStore
you need to .New() a store in order to GetAsync on its returned object

1 Like

Thank you. I’ll try this

charcountnoway