#DataStore

1 messages · Page 1 of 1 (latest)

frigid heron
#

this uses the youtube tutorial that suphi made

It seems that to save the coins leaderstat, the developer product has to be bought. What would I do to just make the coins leaderstat save when the player leaves the server, not when the developer product is bought?

idle basalt
#

Are you using suphi module or your own datastore

frigid heron
idle basalt
#

The module already automatically saved when player leaves. How are you doing the saving

frigid heron
#

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

idle basalt
#

Can you show me how you are doing it. Because you really just have to update datastore.value

frigid heron
#
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

idle basalt
#

and how are you testing this (What do you do to change the coins in leaderstats to test it)

idle basalt
#

?

frigid heron
#

changing the coins value

idle basalt
#

yea that wouldnt work lmao

frigid heron
#

why not?

idle basalt
#

because the datastore have no idea you changed the value of the numberValue

frigid heron
#

so how would I test it

#

lets say I had a robbery

idle basalt
#

just set the value directly

frigid heron
#

and when the player robs it and awards the coins

idle basalt
#

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

frigid heron
#

i sent the scripts

idle basalt
#

ok then

#

datastore.value.Coins = yourValue

frigid heron
#

where

idle basalt
#

anywhere you like.

frigid heron
#

when I'm in the game?

idle basalt
#

no before

#

thats how you check if the datastore saves

frigid heron
#

but what if the player gets money whilst in the game from a robbery

#

and the cash is awarded

idle basalt
#

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

frigid heron
#

hm

#

when the numberValue is changed, the data store saves it?

idle basalt
#

yes

#

and how do you let the datastore know it changed

frigid heron
#

how would you let it know?

idle basalt
#

first of all do you know how to save your stuff in datastore

frigid heron
#

no

#

well

#

the dataStore module does it for me

idle basalt
#

it does but the datastore would only save what it currently know

frigid heron
#

wait

#

im sorry

#

are we able to continue this conversartion in like 20 mins?

idle basalt
#

👍

frigid heron
#

alright thank you

frigid heron
#

@idle basalt back

#

alright

#

lets continue shall we

warm magnet
#

My braincells just died reading this

junior vine
#

@frigid heron you are doing it so inefficiently

#

let me get on pc and show 1 sec

junior vine
frigid heron
frigid heron
#

why would they be made to screw me over lol

warm magnet
#

How long have you been on the internet?

frigid heron
#

alright

junior vine
frigid heron
#

no need for that

#

im just saying, they dont screw me over

junior vine
idle basalt
#

this guy is literally using suphis module wtf are u even talking about

frigid heron
#

fr idk what they are

idle basalt
#

instead of judging him just help him out

frigid heron
#

well

#

thats what most people do to beginner scripters now

#

in all discord servers

warm magnet
frigid heron
#

i am

idle basalt
frigid heron
#

frr

junior vine
#

@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)

idle basalt
#

💀

junior vine
# idle basalt 💀
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 😔
idle basalt
#

LMAO

junior vine
#
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

frigid heron
#

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

idle basalt
#

well before you copy his dog sht script

frigid heron
#

im not

idle basalt
#

yes

#

his datastore works by saving the datastore.value

#

so you have to feed it the updated value of your numValue

frigid heron
idle basalt
#

theres multiple ways you can achieve this

#

i can name 2 ways

frigid heron
idle basalt
#

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
frigid heron
#

for this method

idle basalt
#

nope

frigid heron
#

alright thats simple enough

idle basalt
#

if you really want to have it changed

#

when you change the numberValue

frigid heron
#

i was thinking of changing the whole script so that it saves the numberValue when it is changed

spark ledge
#

Side question: how fast can you rewrite specific data values in a data store?

idle basalt
#

you can then use signals.

numberValue.PropertChangedt

idle basalt
frigid heron
#

ill read about it

idle basalt
#

if you encounter more problems let me know imma go to work now

frigid heron
#

thank you

idle basalt
#

wym exactly. If you are talking about writing to the same datastore key they removed the 6s cooldown

#

With suphis module you don't really have to worry about writing on the same key since the only time his datastore is being saved is during the save interval, close/destroy methods.