Best method to get table data to client for in-game shop?

It’s my first time dealing with an in-game shop/upgrade system. I currently need help to know the best way to do an “owned” system. I’d appreciate it if any of the two examples at the bottom of this post would be a decent method for doing a system like this.

Here is an example of the upgrades frame (not coded yet), where ITEM2 is selected and not already owned. But this has almost nothing to do with the question at all;

image

The data could possibly look like this for a player:

local Shops = {
	ShopOne = {
		ITEM1 = true, -- owned.
		ITEM2 = false, -- not owned.
		ITEM3 = false -- not owned.
	}
}

Example 1:

When the player is in the physical-range of ShopOne, the Shop frame opens and the client receives the table/data. The received table/data then sorts the shop with what already is owned or not. Does this have to be done using a Remote Function since it is Client > Server > Client or would it be possible using a Remote Event and how could it be done?

Example 2:

Your own example if you know another or better method…

1 Like

You could use a RemoteFunction asking the server to retrieve the player’s data table, and then you can use that to update the buttons. (ex: making the text say “Buy for X coins” or “Already Owned”.) Just make sure to use the table as a read-only object; to prevent exploiting. Basically like, just reading the data to determine what to draw on the UI elements, and then when the player attempts to buy something you can then call a RemoteEvent to the server with the item name the player wants to buy. Or, you could utilize a RemoteFunction and have it return a true/false state indicating if the purchase was successful, so you could update the text again with the value returned.

Hope this helps, if you need more clarification or help let me know :slight_smile:

2 Likes

That was really good explained and I’ll do exactly what you said. The only issue is that I am not sure how to return the table to the client?

1 Like

Okay so, I assume you have a data system already set up on the server that handles storing and indexing player data.

Assuming it looks something like this:

local player_data = {
["ANoobPlayer123"] = {}; --//Whatever player data
}

If not, I’d recommend you store player data in a format like that, it makes it much easier to work with, especially in this case.

Then, it’s a really simple process. Just connect a RemoteFunction to a function, and have it return the player’s data stored in player_data:

SomeRemoteFunction.OnServerInvoke = function(playerWhoCalled)
    return player_data[playerWhoCalled].Name --//Index and return the player's data
end)

Hope this makes sense.

2 Likes