Datastore Module (Simple to use, yet life saving!)

Hi! :wave:

–// I’ve made a simple but yet life saving module.
This is my data store module that helps you store data in just a second.

If you want to try it out, here’s the module.

Module:

[=======================================================]

Here’s an example code.

local CurrentPlayer
local DataModule = require(game.ReplicatedStorage.DataModule)

game.Players.PlayerAdded:Connect(function(player) --// If player joins.
	local value = Instance.new("IntValue") --// Creates the value.
	value.Parent = player --// Sends it to the Player's Profile.
	value.Name = "Coins" --// Names the Value.

    CurrentPlayer = player
	
	DataModule.SaveData(player, value) --// Loads the data; "player" is the "Player"; value is the "Value".
end)

game.Players.PlayerRemoving:Connect(function(player) --// If player left.
	DataModule.LoadData(player, player.Coins) --// Saves the data; "player" is the "Player"; "player.Coins" is the "Value" we added before.
end)

game:BindToClose(function() --// Check if server shutdowns
	DataModule.BindToClose(CurrentPlayer.Coins)  --// Save the data.
end)

You can save 2 or more datas in just a script!

NOTE: You can add the module anywhere as long as you can find it by script.

–// Testing video using BindToClose

Changelog

v0.1:

  • Fixed BindToClose not saving data.
  • Added Datastore support up to 10 datastores in one script.

v0.2:

Upcoming
  • work with :UpdateAsync.
12 Likes

Can i ask a question? isn’t the player supposed to save data when leaving and load data when joining? (the words kinda mess me up a little)
Also is this going to work with game:BindToClose(function() ?

3 Likes

Yes, it’s gonna work with both, And no, it’s just like i did but i think i made it inverse by mistake.

3 Likes

Ah alright, thanks for the clarification mate! I’ll definitly use this in one of my projects hopefully!

2 Likes

You’re welcome!

Summary

(30charasrrssrsrsrs)

3 Likes

Welp, i have a question tho.
Isn’t game:BindToClose(function() the same as game.Players.PlayerRemoving?

3 Likes

No, say if there was one player in the server, when he leaves the server gets shutted down, that means PlayerRemoving won’t fire, that’s why people use game:BindToClose(function(),

+When a game gets their server shutted down, the players’ data won’t be saved without game:BindToClose(function()

1 Like

Yeah, i’ll try to look on that and make it work for my module.

3 Likes

I’ve made it work. Hopefully it doesn’t gets messed up.

3 Likes

why require the module every time when you could just make a variable for it once

local DataModule = require(game.ReplicatedStorage.DataModule)
game.Players.PlayerAdded:Connect(function(player) --// If player joins.
	local value = Instance.new("IntValue") --// Creates the value.
	value.Parent = player --// Sends it to the Player's Profile.
	value.Name = "Coins" --// Names the Value.
	
	DataModule.SaveData(player, value) --// Saves the data; "player" is the "Player"; value is the "Value".
end)

game.Players.PlayerRemoving:Connect(function(player) --// If player left.
	DataModule.LoadData(player, player.Coins) --// Load the data; "player" is the "Player"; "player.Coins" is the "Value" we added before.
end)

game:BindToClose(function() --// Check if server shutdowns
	DataModule.BindToClose(CurrentPlayer.Coins)  --// Save the data.
end)
4 Likes

Well, that was just a testing script, i forgot to list it like that, my bad.

2 Likes

The huge problem with this module is no additonal attempts whenever it errors, data loss chance :chart_with_upwards_trend:

2 Likes

ProfileService, DS2 and some other datastores are actually pretty difficult to understand to most new scripters, and naturestore’s way of saving data (talking about IncrementData) is something not everyone enjoys using

I feel like this module is great for new scripters to get started with saving data as roblox’s default datastore is hard to understand for most.

3 Likes

Those modules are for experienced developers that knows how to use it. Mine is for new developers. I’ll try my best to make it better so no data loss occurs.

1 Like

I’ve came back to tell people that instead of Loading data with

DataModule.LoadData(player,value)

You’ll have to inverse things, Save Data when player joins and load data when player leaves, i’ll come back to this module and fix this thing.

DataModule.SaveData(player,value)
1 Like