Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can anyone help me fix this difficult datastore bug?

Asked by
St_vnC 330 Moderation Voter
5 years ago

I have problems with my RPG datastore here's save/Load data part of the script :

001local Players = game:GetService("Players")
002local DataStoreService = game:GetService("DataStoreService")
003local RunService = game:GetService("RunService")
004local ReplicatedStorage = game:GetService("ReplicatedStorage")
005 
006local DataStore = DataStoreService:GetDataStore('Data')
007 
008-- Settings
009local StarterData = {
010    MaxChar = 5;
011    LStats = {
012        Lvl = 1;
013        XP = 0;
014        Coins = 0;
015    };
View all 154 lines...

I always have problems saving data(outside of studio) it keeps printing the error message when I see no errors. I'm pretty sure I didn't exceed the DataStore budget limit, you can check if I'm wrong tho. This DataStore system is based on Mystifine's system https://www.youtube.com/watch?v=at9Yhjt572c

1 answer

Log in to vote
0
Answered by 5 years ago

Ok, lets try it

Firs Step : We need to know how to acces to the DataStoreService and how it works! So lets see how we can get the service!

1local ds = game:GetService("DataStoreService")
2--> This is all! Is a service of the Instance "game" so you can get it with `GetService()`

That's how we get the DataStoreService in one simple line of code!

Second Step : Second, we need to know how to use correctly the DataStore so we have to make another variable that contains the data of the currency or etc we want to Store on the service!

1local ds = game:GetService("DataStoreService")
2local moneyDs = ds:GetDataStore("moneyData")
3--[[
4    This is all! The service "DataStore" have a function to get the Data already stored in
5    so we called with the function "GetDataStore"
6]]

That's how we create a variable with the data we want to save. So lets make now a leaderstats functional with the SaveData

Third Step : Enjoy coding! You always have to enjoy what are you doing! Play some music while you script or even you can play a game before to be relaxed!

Lets get into code!

01local ds1 = game:GetService("DataStoreService")
02local moneyDs = ds1:GetDataStore("moneyData")
03local ds2 = game:GetService("DataStoreService")
04local xpDs = ds2:GetDataStore("xpData")
05local ds3 = game:GetService("DataStoreService")
06local lvlDs = ds3:GetDataStore("levelData")
07local ds4 = game:GetService("DataStoreService")
08local rxpDs = ds4:GetDataStore("requiredxpData")
09 
10game.Players.PlayerAdded:Connect(function(plr)
11    local folder = Instance.new("Folder", plr)
12    folder.Name = "leaderstats"
13 
14    local money = Instance.new("IntValue", folder)
15    money.Name = "Money"
View all 61 lines...

That's how we use the DataStore correctly and easy. I write all the code here on scriptinghelpers so that's the why I don't answer faster.

I hope my answer already solve your question! If its like that please accept my answer. That will help me a lot!

Keep scripting!

0
That’s great but I don’t want to copy and paste. Also I want to know what’s wrong in my code St_vnC 330 — 5y
0
Ok, I'll explain you on Discord. Foxy_Developer 111 — 5y
0
But later, I'll check the advanced DataStore function. And I'll try to explain you how it works. Cya Foxy_Developer 111 — 5y
Ad

Answer this question