#how to make datastore for leaderstats

110 messages · Page 1 of 1 (latest)

abstract hemlock
#

Also I had a problem of changing the leaderstats when the datastore is there

#

Pls help me 😢

peak dune
#

getasync setasync!!!

frigid walrus
peak dune
#

wooooo

peak dune
abstract hemlock
#

But when I try and change it

#

With scripts did doesn’t save

#

It

peak dune
#

did you enable datastore service thingy

#

in ur game

abstract hemlock
frigid walrus
#

so what you want us to do, read code from your mind

frigid walrus
#

send. code. so. we. can. check. whats. wrong.

abstract hemlock
#

Okay.

frigid walrus
#

we need info

peak dune
#

yez

#

give us the puzzle so we can solve

frigid walrus
#

i

abstract hemlock
#

I deleted it 💀

quick frigateBOT
#

studio** You are now Level 2! **studio

abstract hemlock
#

Like before

peak dune
#

what da hell

abstract hemlock
#

Hold up

peak dune
#

did you just copy it 1 to one orr

#

you changed it a bit and then it just didn't work

abstract hemlock
#

local DataStoreService = game:GetService("DataStoreService")
local dataStore = DataStoreService:GetDataStore("MyDataStore") -- This can be changed to whatever you want

local function saveData(player) -- The functions that saves data

local tableToSave = {
    player.leaderstats.Money.Value; -- First value from the table
    player.leaderstats.Coins.Value -- Second value from the table
}

local success, err = pcall(function()
    dataStore:SetAsync(player.UserId, tableToSave) -- Save the data with the player UserId, and the table we wanna save
end)

if success then -- If the data has been saved
    print("Data has been saved!")
else -- Else if the save failed
    print("Data hasn't been saved!")
    warn(err)        
end

end

game.Players.PlayerAdded:Connect(function(player) -- When a player joins the game

-- // Assigning player stats //
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player

local Money = Instance.new("IntValue")
Money.Name = "Money"
Money.Parent = leaderstats

local Coins = Instance.new("IntValue")
Coins.Name = "Coins"
Coins.Parent = leaderstats

local data -- We will define the data here so we can use it later, this data is the table we saved
local success, err = pcall(function()

    data = dataStore:GetAsync(player.UserId) -- Get the data from the datastore
    
end)
#

if success and data then -- If there were no errors and player loaded the data

    Money.Value = data[1] -- Set the money to the first value of the table (data)
    Coins.Value = data[2] -- Set the coins to the second value of the table (data)
    
else -- The player didn't load in the data, and probably is a new player
    print("The player has no data!") -- The default will be set to 0
end

end)

game.Players.PlayerRemoving:Connect(function(player) -- When a player leaves
local success, err = pcall(function()
saveData(player) -- Save the data
end)

if success then
    print("Data has been saved")
else
    print("Data has not been saved!")
end

end)

game:BindToClose(function() -- When the server shuts down
for _, player in pairs(game.Players:GetPlayers()) do -- Loop through all the players
local success, err = pcall(function()
saveData(player) -- Save the data
end)

    if success then
        print("Data has been saved")
    else
        print("Data has not been saved!")
    end
end

end)

peak dune
#

is that from the tutorial

abstract hemlock
#

Like if I try changing the leaderstats

abstract hemlock
#

It doesn’t save

peak dune
#

what are you changing

abstract hemlock
#

Leaderstats value

#

Like the coins value

#

It I change that value

peak dune
#

ur just changing the amount

#

thats it?

abstract hemlock
#

With like a script

abstract hemlock
#

But it just resets to 0

#

When I rejoin

peak dune
#

what line did you change the value at

abstract hemlock
peak dune
#

Coins.Parent = leaderstats
did you do it after this line

abstract hemlock
#

Player.leaderstats.coins.value = 10

#

Like I added a line

peak dune
#

yes but where

peak dune
abstract hemlock
#

After the wher it stats the leaderstats function

#

States

#

Above playerremovinng

#

@peak dune

peak dune
#

the line before playerremoving?

abstract hemlock
peak dune
#

did you put the line inside of player removing or player added

#

or did you put the line outside of the two

abstract hemlock
abstract hemlock
peak dune
#

so outside

abstract hemlock
#

Loutside

peak dune
#

ok can i ask

#

why are you changing the players coin value

abstract hemlock
#

Cause I wanted to see if it worked?

#

Like I need it later

#

How was I supposed to changed it

peak dune
#

if you press play

#

you can go on server side and change your coins stat

#

dont ask me how, just search it up

abstract hemlock
#

Ye I tried that too

#

Doesn’t work

peak dune
#

no you probably done it on the client side

abstract hemlock
#

Like u don’t press switch client?

#

right?

peak dune
#

current:server

abstract hemlock
#

Never pressed it

#

And it not work

peak dune
#

when you join it says client

abstract hemlock
#

Ye I didn’t press it

#

Oh

peak dune
#

if you want to change the coins value, click it and go serversided and change it

abstract hemlock
#

Ohhh

#

So when u play

quick frigateBOT
#

studio** You are now Level 3! **studio

abstract hemlock
#

It is client?

peak dune
#

watch a tutorial about client and serverside

abstract hemlock
#

Ohhhhhh

#

Thx

#

Wait

peak dune
#

np

abstract hemlock
#

1 more questions

#

How would I go about changing the lease

#

Leaderstats

#

With scripts

peak dune
#

wdym

abstract hemlock
#

Like I want it change it with scripts how would I do it

#

The leaderstats

#

@peak dune

peak dune
#

i still dont get what you mean

#

do you want to change the coins name to something else or what

abstract hemlock
#

Like how would I change the leaderstats with scripts

peak dune
#

you access the leaderstats folder from the player

#

then change it from there

abstract hemlock
#

Ohh ok