Creating posts like a forum in-game?

The title seems confusing, well, what I want to do is make something like posts, or threads, like in Lua Learning:

I don’t want to make the entire system, I want to do stuff like writing something and that will be saved in the server, and you can read it. I tried with datastores, but the requests might be alot in my game, which will make the requests be throttled. How do I achieve this? Thanks for reading :+1: :123:

3 Likes

You could message the person who’s responsible for developing this first and see if they’re willing to impart that knowledge or some guidance regarding accomplishing this.

cc @boatbomber

2 Likes

Honestly if the game is single player, then I doubt you’ll hit the request throttle. I’m assuming you want it so the posts can save and be loaded throughout different servers right?

They might also be using HTTPService.

1 Like

I thought that, but the game is multiplayer…

1 Like

I made something a little similar for a game called “Trade Central”: Trade Central - Roblox

Sadly due to the lack of requests per minute roblox gives, you’ll need to ration how many posts they can create per minute. The datastore limit is: 60 + numPlayers × 10

That means a single user if you want can create 1 thread every minute, and possibly 9 replies per minute. The only issue I’ve gotten though when doing this was when the datastores try to update too fast and the queue overflows. At that point what I decided to do was to use httpservice so that I could handle the incoming posts on my own without the terribly slow update queue.

With messaging service being a thing, I bet you could come up with a method that sort of creates a table of current threads in each server, and then saves the table to a datastore later on. It would be a wonky implementation that would prob take a little while to understand and get to be efficient, but I do believe it could be an alternative.

2 Likes

What if the game gets a shutdown? The problem is that the data will not be saved.

That’s where the bindtoclose event comes in. When a server gets shutdown or a server ends, you can use the bindtoclose event to check for that. Doing so also allows you to keep the server open for a slightly longer amount of time which can prevent data corruption upon users.

Inside the bindtoclose event function all you need to do is save the current table of forum posts to a datastore. It may not be the most efficient way, but it beats having to make an entire database for a website

1 Like

Yeah, but I don’t think I should use datastore, maybe boatbomer’s possible reply will answer this question…

I honestly don’t see a very efficient way of going about doing what you want considering roblox has a pretty terrible system for cross server communication atm. Their roadmap had some interesting stuff such as universal scripts and temporary data stores. If you want to wait for those upcoming additions then do so. Otherwise I’d recommend using http service

Lua Learning uses DataStores.

It uses a custom distributed key module I wrote so that it can store more than the 260000 limit, but for example’s sake, assume it’s one key.

I store the posts as so:

local Posts = {
	[PostID] = {
		Info = {
			Title = "String";
			Description = "String";
			AuthorID = 1;
			Date = os.time();
			-- Various more info
		};
		Content = "String of **Markdown** text.";
	};
	[PostID] = {
		Info = {
			Title = "String";
			Description = "String";
			AuthorID = 1;
			Date = os.time();
			-- Various more info
		};
		Content = "String of **Markdown** text.";
	};
 };

local function Save()
 -- Save Posts using my DataStore module
 -- Use messaging service to notify servers that there's a new post
end

When a player joins, they fire a RemoteFunction called GetPosts, and the server returns the cached posts table.

Not terribly complicated. The hard part is the caching and key distribution.

7 Likes

A better way of doing it is having the server get it once and storing it all within a table. That way when a new player joins, it’s not preforming a data store request call. Anyways I can try to come up with a basic system that can get what you need done

That’s the caching part. Notice how I said return the table, not calls the DataStore.

o lol whoops my bad I didn’t read it clearly

Could you explain me what is caching? Also, that saving module, you have published it? So i can use it :slight_smile:

I’m sure you can find a plethora of resources on it, since it’s a core subject of programming.

I haven’t, since a lot of it is hardcoded to Lua Learning’s use case (for efficiency) so it won’t really work for other people.

2 Likes