How would i go about getting player data on other scripts?

So, lets say this is the player data in a script in ServerScriptService:

local data = {
	PurchasedCharacters = {"Char1","Char2"} -- and so on
    PurchasedSkins = {"Gunman"}
}

And now if i wanted to access that data on a LocalScript in a store GUI that displays which characters are purchased and which are not, how would i do this?

Hi,you could use Remote Events.

To communicate between the server and the client, you can use remote events, which is a one-way communication method, or remote functions, a two-way communication method. In this case, you want to tell the server you want the data for, lets say, NoobinBizniz. Then, you want the server to actually give the client that data. A great way to do this is with remote functions.
Some pseudocode:

LocalScript:

--Whatever logic you have placed
     game.ReplicatedStorage.RequestPlayerDaya:InvokeServer()

ServerScript:

local data = { --probably not the best idea to store data here but this is just psuedocode
     ["NoobinBizniz"] = {
          PurchasedCharacters = {"Char1","Char2"}
          PurchasedSkins = {"Gunman"}
     }
}

RequestPlayerData.OnServerInvoke = function(player)
	local playerData = data[player.Name]
	if playerData then
		return playerData
	else
		return {
			PurchasedCharacters = {},
			PurchasedSkins = {}
		}
	end
end

Thanks! I wrote it in my game and it works great.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.