#How to make datastorage for currencys "Clicks, rebirths, gems"

147 messages · Page 1 of 1 (latest)

abstract heath
#

at top of leaderstats- ```local DSS = game:GetService('DataStoreService')
local CurrencyDataStore = DSS:GetDataStore('CurrencyDataStore')

local function saveData(player)
if player:FindFirstChild("leaderstats") then
local toSave = {
gems = player.leaderstats.Gems.Value;
clicks = player.leaderstats.Clicks.Value;
rebirths = player.leaderstats.Rebirths.Value;
}

        local success, erorrMessage = pcall(function()
            CurrencyDataStore:SetAsync(player.UserId.."-Currency",toSave)
        end)

        if success then
            print("Data Saved")
        
        else print("Error: "..erorrMessage)
        end
    end
    end```
#

then that function can go rly anywhere

#

i just copied my script

#

its not all of it

#

its on the internet for free prob

#

then this is loading part

#

yeah then put the function under that

#

but something needs to go abvoe the function

#

above

#

let me do it rq

#

1s

#

also

#

dont copy that other part

#

i messed up the key

#

1s

#

ok good

#

u can copy the function now

#

under leaderstats

#

this will be above that function

#

im making it rn

#

function must go under the loading part

#

yeah

#

then i have to make something for that

#

gimmi 5m

#

no

#

almost

#

u need some more things 1s

#
  local gemData = data.gems
  local clickData = data.clicks
  local rebirthData = data.rebirths

    if data then 
        player.leaderstats.Gems.Value = gemData
        player.leaderstats.Rebirths.Value = rebirthData 
        player.leaderstats.Clicks.Value = clickData 
    end```
#

put that above the function

#

idk if u need two equal signs or 1 i forget

#

put it and see if theres any red lines

ember thistleBOT
#

studio** You are now Level 7! **studio

abstract heath
#

1 more thing

#

this

#
        saveData(player)
    end)
    
    game:BindToClose(function()
        for i, player in pairs(game.Players:GetPlayers()) do
            saveData(player)
        end
    end)```
#

put that underneath savedata

#

yeah

#

try it

#

wait

#

no

#

u did it wrong

#

u piut in in wrong

#

u put that in the middle of the functiopn

#

put it under the function

#

the game.Players.PlayerRemoving:Connect(function(player)
saveData(player)
end)

game:BindToClose(function()
    for i, player in pairs(game.Players:GetPlayers()) do
        saveData(player)
    end
end)
#

not the the

#

but that thing i just sent you

#

ill do it

#

1s

#
local CurrencyDataStore = DSS:GetDataStore('CurrencyDataStore')

game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local clicks = Instance.new("IntValue")
    clicks.Name = "Clicks"
    clicks.Value = 0
    clicks.Parent = leaderstats

    local rebirths = Instance.new("IntValue")
    rebirths.Name = "Rebirths"
    rebirths.Value = 0
    rebirths.Parent = leaderstats

    local gems = Instance.new("IntValue")
    gems.Name = "Gems"
    gems.Value = 15
    gems.Parent = leaderstats
end)

local data = CurrencyDataStore:GetAsync(player.UserId.."-Currency") 
local gemData = data.gems
local clickData = data.clicks
local rebirthData = data.rebirths

if data then 
    player.leaderstats.Gems.Value = gemData
    player.leaderstats.Rebirths.Value = rebirthData 
    player.leaderstats.Clicks.Value = clickData 
end


local function saveData(player)
    if player:FindFirstChild("leaderstats") then
        local toSave = {
            gems = player.leaderstats.Gems.Value;
            clicks = player.leaderstats.Clicks.Value;
            rebirths = player.leaderstats.Rebirths.Value;
        }




        local success, erorrMessage = pcall(function()
            CurrencyDataStore:SetAsync(player.UserId.."-Currency",toSave)
        end)

        if success then
            print("Data Saved")

        else print("Error: "..erorrMessage)
        end
    end
end


game.Players.PlayerRemoving:Connect(function(player)
        saveData(player)
    end)
    
    game:BindToClose(function()
        for i, player in pairs(game.Players:GetPlayers()) do
            saveData(player)
        end
    end)```
#

that

#

thats ur script

#

or should be

#

yeah

#

send script

#

u def messed it up

#

wait

#

ohh

#

i got it

#

do you have player defined

#

do local player = script.Parent.Parent with the locals

#

it works

#

theres 3

#

LMAO

#

i have atleast 70 in one script

#

i know

#

i told u to define player g

#

yeah

#

yeah i know

#

one second

#

ur script is goofy

#
local DSS = game:GetService('DataStoreService')
local CurrencyDataStore = DSS:GetDataStore('CurrencyDataStore')


game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local clicks = Instance.new("IntValue")
    clicks.Name = "Clicks"
    clicks.Value = 0
    clicks.Parent = leaderstats

    local rebirths = Instance.new("IntValue")
    rebirths.Name = "Rebirths"
    rebirths.Value = 0
    rebirths.Parent = leaderstats

    local gems = Instance.new("IntValue")
    gems.Name = "Gems"
    gems.Value = 15
    gems.Parent = leaderstats


local data = CurrencyDataStore:GetAsync(player.UserId.."-Currency") 
local gemData = data.gems
local clickData = data.clicks
local rebirthData = data.rebirths

if data then 
    player.leaderstats.Gems.Value = gemData
    player.leaderstats.Rebirths.Value = rebirthData 
    player.leaderstats.Clicks.Value = clickData 
end


local function saveData(player)
    if player:FindFirstChild("leaderstats") then
        local toSave = {
            gems = player.leaderstats.Gems.Value;
            clicks = player.leaderstats.Clicks.Value;
            rebirths = player.leaderstats.Rebirths.Value;
        }




        local success, erorrMessage = pcall(function()
            CurrencyDataStore:SetAsync(player.UserId.."-Currency",toSave)
        end)

        if success then
            print("Data Saved")

        else print("Error: "..erorrMessage)
        end
    end
end


game.Players.PlayerRemoving:Connect(function(player)
    saveData(player)
end)

game:BindToClose(function()
    for i, player in pairs(game.Players:GetPlayers()) do
        saveData(player)
        end
    end)
end)```
#

there you go

#

you put the end) which ended the function all the way up there 💀

#
local DSS = game:GetService('DataStoreService')
local CurrencyDataStore = DSS:GetDataStore('CurrencyDataStore')


game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local clicks = Instance.new("NumberValue")
    clicks.Name = "Clicks"
    clicks.Value = 0
    clicks.Parent = leaderstats

    local rebirths = Instance.new("NumberValue")
    rebirths.Name = "Rebirths"
    rebirths.Value = 0
    rebirths.Parent = leaderstats

    local gems = Instance.new("NumberValue")
    gems.Name = "Gems"
    gems.Value = 15
    gems.Parent = leaderstats


local data = CurrencyDataStore:GetAsync(player.UserId.."-Currency") 
local gemData = data.gems
local clickData = data.clicks
local rebirthData = data.rebirths

if data then 
    player.leaderstats.Gems.Value = gemData
    player.leaderstats.Rebirths.Value = rebirthData 
    player.leaderstats.Clicks.Value = clickData 
end


local function saveData(player)
    if player:FindFirstChild("leaderstats") then
        local toSave = {
            gems = player.leaderstats.Gems.Value;
            clicks = player.leaderstats.Clicks.Value;
            rebirths = player.leaderstats.Rebirths.Value;
        }




        local success, erorrMessage = pcall(function()
            CurrencyDataStore:SetAsync(player.UserId.."-Currency",toSave)
        end)

        if success then
            print("Data Saved")

        else print("Error: "..erorrMessage)
        end
    end
end


game.Players.PlayerRemoving:Connect(function(player)
    saveData(player)
end)

game:BindToClose(function()
    for i, player in pairs(game.Players:GetPlayers()) do
        saveData(player)
        end
    end)
end)```
#

copy this

#

yes they do

#

lmfao

#

they work for me

#

some code is blocking it

#

where is this code at

#

no

keen wolf
#

Awesome, but one problem, you need to create a few functions to save and load your data

keen wolf
#

Oh nvm, I was late to the party

abstract heath
#

thats not my problem pandziorka

#

im in the game and it works

#

you messed something up

#

is it in sss

#

yeah

#

it works for me

#

is that the only script in there

#

look through the code

#

should be no red lines

#

no blue lines

#

the code works for me

#

that one u just pasted]

#

its on your end

#

and i dont know

#

anything else altering this script

#

make sure the scripts you use to alter this value is server scripts

#

not local

torn acorn
abstract heath
#

Barely

#

Watch a tutorial

torn acorn
abstract heath
#

Kinda

#

But why would you use that

torn acorn
#

It’s better than normal data store service?

torn acorn
steel dome
steel dome
#

With profile service you don't need to
Setasync
Updateasync
Etc
It does it for you

torn acorn
#

Ah

abstract heath
#

Yeah

#

Just make a table

#

And save it

torn acorn
#

I’m having some problems trying to use it

steel dome
#

Did you read the doc ?

ember thistleBOT
#

studio** You are now Level 20! **studio

torn acorn
#

Should I?

steel dome
#

Yes

torn acorn
#

Can you send link

steel dome
#

The doc is simple to read

torn acorn
#

Is there a way to index a table in a module script

#

Like find one thing inside a table

steel dome
#

local t={}
t.Profile = {}
return r


local M = require(pathtothemodulescript)
M.Profile["hello"] = "world"

torn acorn
#

[] is the table?

steel dome
#

[] is to get an element / create in a table

torn acorn
#

Hmmm

torn acorn
#

Ty ima read it now

near ledge
#

@scarlet geyser u need a better dataStore

near ledge
steel dome
near ledge
# steel dome In some case you need it like w = "hello" t = { hello=1 } t[w] = 2

still u dont need to do that at all this is prob why u dont know this at alllua function reloadData(player) local oldValues = {} for _, players in pairs(player:GetChildren()) do if players:IsA('Folder') then for _,values in pairs(players:GetChildren()) do oldValues[values.Name] = values.Value end end end return oldValues end

steel dome
#

?

#

You just used the []

near ledge
#

also did i ask

abstract heath
#

bro what

#

why r yall in my thread

#

from 2 months ago

#

shit mb it aint mine