#Leaderstats not saving

1 messages · Page 1 of 1 (latest)

limber sundial
#

So my leaderstats are not saving despite me using a datastore script and i did enable api setting so it should work

#

-- Make sure "Enable Studio Access To API Services" is on in Game Settings! (OR IT WON'T WORK) --
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local Saver = DataStoreService:GetDataStore("SaveLeaderstats")

Players.PlayerAdded:Connect(function(player)
local Data = nil
local success, errormessage = pcall(function()
Data = Saver:GetAsync(tostring(player.UserId))
end)

if success then
    if Data then
        for i, v in pairs(Data) do
            player:WaitForChild("leaderstats"):WaitForChild(i).Value = v
        end
    end
else
    error(errormessage)
end

end)

local function Save(player)
local SavedData = {}
for _, v in pairs(player.leaderstats:GetChildren()) do
SavedData[v.Name] = v.Value
end

local success, errormessage = pcall(function()
    Saver:SetAsync(tostring(player.UserId), SavedData)
end)
if not success then
    error(errormessage)
end

end

Players.PlayerRemoving:Connect(Save)

game:BindToClose(function()
for _, v in pairs(Players:GetPlayers()) do
Save(v)
end
end)

#

This is the script i use

#

its a free script i found on yt

cyan trail
#

How do you add ur currency

limber sundial
#

i have different script for that

#

datastore is under this script

cyan trail
#

I just used ChatGPT to do it

brave nest
#
-- Make sure "Enable Studio Access To API Services" is on in Game Settings! (OR IT WON'T WORK) --
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local Saver = DataStoreService:GetDataStore("SaveLeaderstats")

Players.PlayerAdded:Connect(function(player)
    local Data = nil
    local success, errormessage = pcall(function()
        Data = Saver:GetAsync(tostring(player.UserId))
    end)

    if success then
        if Data then
            for i, v in pairs(Data) do
                player:WaitForChild("leaderstats"):WaitForChild(i).Value = v
            end
        end
    else
        error(errormessage)
    end
end)

local function Save(player)
    local SavedData = {}
    for , v in pairs(player.leaderstats:GetChildren()) do
        SavedData[v.Name] = v.Value
    end

    local success, errormessage = pcall(function()
        Saver:SetAsync(tostring(player.UserId), SavedData)
    end)
    if not success then
        error(errormessage)
    end
end

Players.PlayerRemoving:Connect(Save)

game:BindToClose(function()
    for , v in pairs(Players:GetPlayers()) do
        Save(v)
    end
end)
cyan trail
#

And it worked

limber sundial
#

idk about chatgpt i didnt know it could do these scripts

#

ill try asking the assistant thing to make me datastore script

#

yeah the problem isnt in the script

limber sundial
#

i got a script

#

i set it up but it still doesnt work

wintry path
#

What error told you?

limber sundial
#

i even tried multiple scripts

#

no error

#

it just doesnt save

#

and i do have api enabled

#

it should

#

woerk

teal trench
#

try using profilestore instead

limber sundial
teal trench
#

read the docs

limber sundial
#

huh

teal trench
#

its not working so just use profile store

#

its better

limber sundial
#

idk how to use profile stor

wintry path
limber sundial
#

wintry path
#
teal trench
#

i dont know how to explain it i just watched a youtube video https://www.youtube.com/watch?v=m2SP_TLeWHI

You need to be using ProfileStore in all of your Roblox gamedev projects! In this tutorial, we learn why it's better than default Data Stores and how to set it up. No sweat!

Thanks for watching! I'm a Roblox game developer teaching Roblox players how to create their own games. Subscribe to learn more!

Download ProfileStore:
https://create.robl...

▶ Play video
wintry path
#

Hope this help

teal trench
#

and it was clearly easier

wintry path
#

There are different kind method of data saving

brave nest
limber sundial
#

oh

brave nest
teal trench
brave nest
#

send us the script where you create leaderstats etc.

limber sundial
#

game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Rarity = Instance.new("IntValue")
Rarity.Name = "Rarity"
Rarity.Value = 0
Rarity.Parent = leaderstats
local Rolls = Instance.new("IntValue")
Rolls.Name = "Rolls"
Rolls.Value = 0
Rolls.Parent = leaderstats
end)

limber sundial
#

cuz of "for ,"

brave nest
#

so does it work now with fixing ts

limber sundial
#

ok i got the profilestore module

#

its long ag

brave nest
#

I wouldn't recommend profilestore for beginners tbf

limber sundial
#

yeah but

#

datastore wont work either

#

idk why

teal trench
#

You need to be using ProfileStore in all of your Roblox gamedev projects! In this tutorial, we learn why it's better than default Data Stores and how to set it up. No sweat!

Thanks for watching! I'm a Roblox game developer teaching Roblox players how to create their own games. Subscribe to learn more!

Download ProfileStore:
https://create.robl...

▶ Play video
limber sundial
#

i did everything right

teal trench
#

it didnt work aswell for me

limber sundial
#

ok bro 27 mins are we deadass

covert pecanBOT
#

studio** You are now Level 10! **studio

wintry path
#

Rescript it well bit pain thought

teal trench
limber sundial
#

bro rly said "easy to use"

#

1 min in and im bored already

wintry path
limber sundial
#

uhh

#

i got the script but its different than the script in the video

#

and i did download it from it

teal trench
#

its not just 1 script

#

follow the video

limber sundial
#

wgat

teal trench
#

theres a template or whatever

#

and the core module

#

and a data manager

limber sundial
#

uhh

teal trench
#

then u can just use that class to save data / retrieve it

wintry path
#

dude? feel like more lecture

limber sundial
#

dos it manage only leaderstats or what

teal trench
#

u can save anything to it

limber sundial
#

oh

wintry path
#

hehe @limber sundial

limber sundial
#

??

#

i dont get it

wintry path
#

i got all free time @limber sundial

limber sundial
#

?

#

so lie

#

u do it for me?

#

@wintry path

#

??

wintry path
limber sundial
#

bro im finishing the profile store

#

if it doesnt work istg

wintry path
limber sundial
#

im pretty sure i must have you added to give u access

wintry path
#

what ur user?

limber sundial
#

MOO_OOOI

wintry path
#

fast friends request incoming

limber sundial
#

there you go

#

i gave you access

#

keep in mind i have the game saved so it doesnt matter if ur brewing something malicious

#

and dont ask what is this game about

wintry path
#

i understand have work with my friend game

covert pecanBOT
#

studio** You are now Level 13! **studio

limber sundial
#

?

wintry path
#

here is my version

#

it took me long write it

limber sundial
#

so

#

do i just delete whati just wrote?

#

imma try it out

wintry path
#

ok

limber sundial
#

yeah it doesnt work

#

try it urself

wintry path
#

i did try in my place

limber sundial
#

and it worked?

#

yeah it doesnt in mine

#

i also have to go now, if u want you can try to finish the profilestore or edit whatever you created and make sure to tell me what have you done while i was gone

limber sundial
wintry path
limber sundial
limber sundial
#

Can you help somehow?

teal trench
#

hmm

#

make an folder in replicated storage and put the modules there

deft bay
#

bro data saving not hard

ruby hamlet
#

@limber sundial i gotchu

#

@limber sundial -- Make sure "Enable Studio Access To API Services" is on in Game Settings! (OR IT WON'T WORK) --
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local Saver = DataStoreService:GetDataStore("SaveLeaderstats")

Players.PlayerAdded:Connect(function(player)
local Data = nil
local success, errormessage = pcall(function()
Data = Saver:GetAsync(tostring(player.UserId))
end)

if success then
    if Data then
        for i, v in pairs(Data) do
            player:WaitForChild("leaderstats"):WaitForChild(i).Value = v
        end
    end
else
    error(errormessage)
end

end)

local function Save(player)
local SavedData = {}
for _, v in pairs(player.leaderstats:GetChildren()) do
SavedData[v.Name] = v.Value
end

local success, errormessage = pcall(function()
    Saver:SetAsync(tostring(player.UserId), SavedData)
end)
if not success then
    error(errormessage)
end

end

Players.PlayerRemoving:Connect(Save)

game:BindToClose(function()
for _, v in pairs(Players:GetPlayers()) do
Save(v)
end
end)