#DataStore
1 messages · Page 1 of 1 (latest)
Are you using suphi module or your own datastore
suphi's
The module already automatically saved when player leaves. How are you doing the saving
not for me
if i change the coins leaderstat for the player whilst in the game, and rejoin the game, the coins leaderstat does not save
when I purchase the developer product, and it gives me the cash, and rejoin the game, the coins leaderstat saves
Can you show me how you are doing it. Because you really just have to update datastore.value
local DataStoreModule = require(game.ServerStorage.DataStore)
local keys = {"Coins",}
local function StateChanged(state, dataStore)
if state ~= true then return end
for index, name in keys do
dataStore.Leaderstats[name].Value = dataStore.Value[name]
end
end
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
for index, name in keys do
local intValue = Instance.new("IntValue")
intValue.Name = name
intValue.Parent = leaderstats
end
local dataStore = DataStoreModule.new("Player", player.UserId)
dataStore.Leaderstats = leaderstats
dataStore.StateChanged:Connect(StateChanged)
end)
leaderstat script
local DataStoreModule = require(game.ServerStorage.DataStore)
local template = {
Coins = 0,
}
local function StateChanged(state, dataStore)
while dataStore.State == false do
if dataStore:Open(template) ~= "Success" then task.wait(6) end
end
end
game.Players.PlayerAdded:Connect(function(player)
local dataStore = DataStoreModule.new("Player", player.UserId)
dataStore.Player = player
dataStore.StateChanged:Connect(StateChanged)
StateChanged(dataStore.State, dataStore)
end)
game.Players.PlayerRemoving:Connect(function(player)
local dataStore = DataStoreModule.find("Player", player.UserId)
if dataStore ~= nil then dataStore:Destroy() end
end)
player data script
local MarketplaceService = game:GetService("MarketplaceService")
local DataStoreModule = require(game.ServerStorage.DataStore)
local products = {
[1712861692] = function(receiptInfo)
local dataStore = DataStoreModule.find("Player", receiptInfo.PlayerId)
if dataStore == nil then return Enum.ProductPurchaseDecision.NotProcessedYet end
if dataStore.State ~= true then return Enum.ProductPurchaseDecision.NotProcessedYet end
dataStore.Value.Coins += 1000000
if dataStore:Save() == "Saved" then
dataStore.Leaderstats.Coins.Value = dataStore.Value.Coins
return Enum.ProductPurchaseDecision.PurchaseGranted
else
dataStore.Value.Coins -= 1000000
return Enum.ProductPurchaseDecision.NotProcessedYet
end
end,
}
MarketplaceService.ProcessReceipt = function(receiptInfo)
return products[receiptInfo.ProductId](receiptInfo)
end
developer product script
@idle basalt
and how are you testing this (What do you do to change the coins in leaderstats to test it)
?
changing the coins value
yea that wouldnt work lmao
why not?
because the datastore have no idea you changed the value of the numberValue
just set the value directly
and when the player robs it and awards the coins
like datastore.value.Coins = 4
idk what your table looks like so im assuming coins is a table
just adjust that to how your table is set up
or dictionary
i sent the scripts
where
anywhere you like.
when I'm in the game?
but what if the player gets money whilst in the game from a robbery
and the cash is awarded
you know what
lets go through this logically
So our problem is the datastore dont know aboutthe numberValue in your leaderstat folder
what do you think should we do
I have to do it this way because you will ask more question about verything pretty much
how would you let it know?
first of all do you know how to save your stuff in datastore
it does but the datastore would only save what it currently know
👍
alright thank you
My braincells just died reading this
first, you dont need two scripts for leaderstat/ loading data
alr
well thats how the yt video did it
why would they be made to screw me over lol
How long have you been on the internet?
alright
first for making instances for your datastore i'd use a function (since you will be making a lot of instances..)
local function instance(class, properties)
local ins = instance.new(class)
for i,v in properties do
inst[i] = v
end
end
this guy is literally using suphis module wtf are u even talking about
fr idk what they are
instead of judging him just help him out
You're learning 
how do you even know his making alot of instances when he literally just have a coin value
frr
1 sec
@frigid heron
local DataStoreModule = require(game.ServerStorage.DataStore)
local template = {
leaderstats =
{
Coins = 0,
}
}
local function instance(class, properties)
local ins = instance.new(class)
for i,v in properties do
ins[i] = v
end
end
local function StateChanged(state, dataStore)
while dataStore.State == false do
if dataStore:Open(template) ~= "Success" then task.wait(6) end
end
end
game.Players.PlayerAdded:Connect(function(player)
local dataStore = DataStoreModule.new("Player", player.UserId)
StateChanged(dataStore.State, dataStore)
dataStore.StateChanged:Connect(StateChanged)
local ls = instance("Folder", {Name = "leaderstats", Parent = player})
for i,v in template["leaderstats"] do
if typeof(v) == "number" then
instance("NumberValue", {Name = i, Parent = ls, Value = v})
elseif typeof(v) == "string" then
print("so on, so forth")
end
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local dataStore = DataStoreModule.find("Player", player.UserId)
if dataStore ~= nil then dataStore:Destroy() end
end)
💀
local suphi = require(game:GetService("ServerScriptService").modules.dataStore)
local template = require(script.template)
local function newInst(Class, Properties)
local a = Instance.new(Class)
for i,v in pairs(Properties) do
a[i] = v
end
return a;
end
local function StateChanged(state, dataStore)
while dataStore.State == false do
if dataStore:Open(template) ~= "Success" then task.wait(6) end
end
end
game.Players.PlayerAdded:Connect(function(player)
local dataStore = suphi.new("Player_", player.UserId, game:GetService("ServerScriptService").modules.dataStore:GetAttribute("Key"))
dataStore.StateChanged:Connect(StateChanged)
StateChanged(dataStore.State, dataStore)
dataStore:Reconcile(template)
if dataStore.Value["Slot"..dataStore.Value.Slot]["CharacterLoaded"] == true then
print('teleport')
end
local pData = newInst("Folder", {Name = player.Name, Parent = game:GetService("ReplicatedStorage").PlayerData})
local slotnum = newInst("StringValue", {Name = "Slot", Parent = pData, Value = dataStore.Value.Slot})
for num = 1, 3 do
local slot = newInst("Folder", {Name = "Slot"..num, Parent = pData})
for i,v in pairs(dataStore.Value["Slot"..num]) do
if type(v) == "table" then
local z = newInst("Folder", {Name = i, Parent = slot})
for nice,thing in pairs(v) do
if type(thing) == "table" then
newInst("StringValue", {Name = nice, Parent = z, Value = table.concat(thing, ":")})
elseif type(thing) == "number" then
newInst("NumberValue", {Name = nice, Parent = z, Value = thing})
elseif type(thing) == "string" then
newInst("StringValue", {Name = nice, Parent = z, Value = thing})
elseif type(thing) == "boolean" then
newInst("BoolValue", {Name = nice, Parent = z, Value = thing})
elseif type(thing) == "userdata" then
newInst("Color3Value", {Name = nice, Parent = z, Value = thing})
end
end
elseif type(v) == "boolean" then
newInst("BoolValue", {Name = i, Parent = slot, Value = v})
elseif type(v) == "number" then
newInst("NumberValue", {Name = i, Parent = slot, Value = v})
elseif type(v) == "string" then
newInst("StringValue", {Name = i, Parent = slot, Value = v})
elseif type(v) == "userdata" then
newInst("Color3Value", {Name = i, Parent = z, Value = v})
end
end
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local dataStore = suphi.find("Player_", player.UserId, game:GetService("ServerScriptService").modules.dataStore:GetAttribute("Key"))
if game:GetService("ReplicatedStorage").PlayerData:FindFirstChild(player.Name) then game:GetService("ReplicatedStorage").PlayerData:FindFirstChild(player.Name):Destroy() end
if dataStore ~= nil then dataStore:Destroy() end -- If the player leaves datastore object is destroyed allowing the retry loop to stop
end)
```this is what i did for mine 😔
LMAO
local template = {
["Slot"] = 1,
["Banned"] = false,
}
template.SlotTemplate = {
["CharacterLoaded"] = false,
["GravityChamber"] = 0,
["Character"] = {
["PrimaryHair"] = 1,
["SecondaryHair"] = #game:GetService("ServerStorage").customizeation.race.hairs:GetChildren(),
["Eyes"] = 1,
["Mouth"] = 1,
["Skin"] = "Burlap",
["Height"] = 1.1,
["Bulk"] = 1.1,
["Race"] = "Human",
["Ability"] = "",
["AbilityRerolls"] = 50,
["Shirt"] = 1,
["Pants"] = 1,
["Shoes"] = 1,
["Accessories"] = {1},
["Mounts"] = {},
["DragonBalls"] = {}
},
["Stats"] = {
["Phys-Damage"] = 0,
["Ki-Damage"] = 0,
["Phys-Resistance"] = 0,
["Ki-Resistance"] = 0,
["Health-Max"] = 0,
["Ki-Max"] = 0,
["Speed"] = 0,
["Moves"] = {},
["Transformations"] = {"Super Saiyan"}
},
["Colors"] = {
-- hair
["PrimaryHairColor"] = Color3.new(1, 1, 1),
["SecondaryHairColor"] = Color3.new(1, 1, 1),
--shirt
["PrimaryShirtColor"] = Color3.new(1, 1, 1),
["SecondaryShirtColor"] = Color3.new(1, 1, 1),
--pants
["PrimaryPantsColor"] = Color3.new(1, 1, 1),
["SecondaryPantsColor"] = Color3.new(1, 1, 1),
--shoes
["PrimaryShoeColor"] = Color3.new(1, 1, 1),
["SecondaryShoeColor"] = Color3.new(1, 1, 1),
-- gamepass
["AuraColor"] = Color3.new(0.152941, 0.803922, 1),
["ChatColor"] = Color3.new(1, 1, 1)
},
["LevelRelated"] = {
["Level"] = 1,
["Prestige"] = 0,
["Rebirth"] = false,
["EXP"] = 0,
["2xTime"] = 0,
["EXPGain"] = 1,
["Zeni"] = 2500,
["SkillPoints"] = 0
},
["RedeemedCodes"] = {},
["QuestSystem"] = {["Current"] = "" },
["Beans"] = {["Current"] = "", ["Red"] = 0, ["Green"] = 0, ["Blue"] = 0, ["Yellow"] = 0},
["Values"] = {
["UltraInstinctDodges"] = 5,
["Ki"] = 100
}
}
for i = 1, 3 do
template["Slot"..i] = template.SlotTemplate
end
return template
heres the template
uhh
ya
i wasn't looking to do that
bro left the thread
@idle basalt are we able to continue the thing we had going before
well before you copy his dog sht script
im not
yes
his datastore works by saving the datastore.value
so you have to feed it the updated value of your numValue
so how would i do that
alright
first is:
When the player robs you give them coins
local function addCoinsAfterRobbed(amount)
local datastore = datastore.find()
local Coins = "Path/To/Your/NumberValue"
-- Your robbed logic here
datastore.Value.Coins += amount
Coins.Value = datastore.Value.Coins
end
so I don't edit the scripts that i sent?
for this method
nope
alright thats simple enough
i was thinking of changing the whole script so that it saves the numberValue when it is changed
Side question: how fast can you rewrite specific data values in a data store?
you can then use signals.
numberValue.PropertChangedt
@frigid heron btw i updated it so numberValue also gets changed when you update the coins from datastore
alright
ill read about it
ah okay
if you encounter more problems let me know imma go to work now
yep alright
thank you
^ @idle basalt
?