#datastorage not functioning

1 messages · Page 1 of 1 (latest)

round cairn
#

Hi so i have a datastorage for my game, and it wont save for some reason? its the XP/LEVELING part that wont save. so if i reach like level 2 and rejoin i am back at level 1. and idk if its my datastorage script or a localscript please help me figure it out someone! (idk which script isnt working)

round cairn
#

so idk what to look for..

little gale
#

uh

#

the datastore

round cairn
#

alr

#
local Players = game:GetService("Players")

local playerDataStore = DataStoreService:GetDataStore("XPLevelData")

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

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

    local Level = Instance.new("IntValue")
    Level.Name = "Level"
    Level.Value = 1
    Level.Parent = leaderstats

    -- Load saved data
    local success, data = pcall(function()
        return playerDataStore:GetAsync(player.UserId)
    end)

    if success and data then
        XP.Value = data.XP or 0
        Level.Value = data.Level or 1
        print("Loaded data for", player.Name, "| XP:", XP.Value, "| Level:", Level.Value)
    else
        if not success then
            warn("Error loading data for", player.Name)
        else
            print("No saved data found for", player.Name)
        end
    end
end)

Players.PlayerRemoving:Connect(function(player)
    local success, err = pcall(function()
        playerDataStore:SetAsync(player.UserId, {
            XP = player.leaderstats.XP.Value,
            Level = player.leaderstats.Level.Value
        })
    end)

    if success then
        print("✅ Saved data for", player.Name, "| XP:", player.leaderstats.XP.Value, "| Level:", player.leaderstats.Level.Value)
    else
        warn("❌ Failed to save player data for", player.Name, ":", err)
    end
end)

#

i used chatgpt to help me but yeah didnt work

#

i got API enabled n etc

little gale
#

any erros?

round cairn
#

none..

#

after getting level 2

#

and i rejoin i get sent back to level 1

#

both on studio and on roblox

little gale
#

lemme see

round cairn
#

how

#

do i invite to studio or

little gale
#

Ill just tell you whats wrong

round cairn
#

okk

little gale
#

just use indexes for loading and saving instead of data.XP and data.Level

#

wait

#

lemme look up if that makes a difference, not sure

round cairn
#

im new to scripting as well.. so idk how that works..

#

and do you feel like joining my project? 😭

little gale
#

not if your using chatgpt to make it

#

unless your paying me

round cairn
#

i aint that good at scripting man

round cairn
little gale
#

wait what game even is this

round cairn
#

i already have a "zone" ish area

#

so once u enter like a dark area it becomes mystic and dark

#

and i have the stamina, health, and xp bar done

#

which works

#

as well as a keybinds ig? for mute, settings etc

little gale
#

is this your first project tho?

round cairn
#

no

#

ive made multiple

#

this time i want to make a somewhat small project or a actual game

#

and if it goes somewhat successful i will focus on it

#

i already got like 1k visits on a old game from 2019

#

no scripting nothing, just simple toolbox items

#

and dark fantasy is kind of a trend on tt rn

little gale
#

are you using toolbox items for this one?

round cairn
little gale
#

well then no

round cairn
#

??

#

i cant fully invest into this yet xd

little gale
#

free models are so dangerous bruh

round cairn
#

if it gets 5-10+ active players or so then ofc i will invest more and get actual modelers/builders

little gale
#

also is your script printing anything

#

because

#

you have print statements

round cairn
#

no it didnt print anything

little gale
#

enable it all

round cairn
#

ah f

little gale
#

what is it saying

round cairn
#

i ended up deleting the orginal playerdatasave script

#

and made a new one

#

and it ended up printing

#

i used indexes

#
local DataStoreService = game:GetService("DataStoreService")

local playerDataStore = DataStoreService:GetDataStore("XPLevelData")

-- === Load Data on Player Join
Players.PlayerAdded:Connect(function(player)
    -- Setup Attributes (safe defaults)
    player:SetAttribute("XP", 0)
    player:SetAttribute("Level", 1)

    -- Try to load data
    local success, data = pcall(function()
        return playerDataStore:GetAsync(player.UserId)
    end)

    if success and data then
        print(":white_check_mark: Loaded data for", player.Name, data)

        player:SetAttribute("XP", data["XP"] or 0)
        player:SetAttribute("Level", data["Level"] or 1)
    else
        if not success then
            warn(":x: Failed to load data for", player.Name)
        else
            print(":detective: No saved data found for", player.Name)
        end
    end
end)

-- === Save Data on Player Leave
Players.PlayerRemoving:Connect(function(player)
    local data = {
        ["XP"] = player:GetAttribute("XP"),
        ["Level"] = player:GetAttribute("Level")
    }

    local success, err = pcall(function()
        playerDataStore:SetAsync(player.UserId, data)
    end)

    if success then
        print(":floppy_disk: Saved data for", player.Name, data)
    else
        warn(":x: Failed to save data for", player.Name, err)
    end
end)

-- === Save Data on Server Shutdown
game:BindToClose(function()
    for _, player in ipairs(Players:GetPlayers()) do
        local data = {
            ["XP"] = player:GetAttribute("XP"),
            ["Level"] = player:GetAttribute("Level")
        }

        local success, err = pcall(function()
            playerDataStore:SetAsync(player.UserId, data)
        end)

        if success then
            print(":floppy_disk: (Shutdown) Saved data for", player.Name, data)
        else
            warn(":x: (Shutdown) Failed to save", player.Name, err)
        end
    end
end)

little gale
#

um

#

why are you using attributes

pastel cairn
little gale
#

also did the old script print anything?

round cairn
blazing spruceBOT
#

studio** You are now Level 6! **studio

pastel cairn
round cairn
#

old scrip uh

#

no

#

it didnt print anything

little gale
#

are you sure

round cairn
little gale
#

you checked all the boxes

round cairn
#

no

#

yes it did print

little gale
round cairn
#

my bad

little gale
#

bruh

#

what does it say

round cairn
#

idk if i should use the new script or js the old one

little gale
#

and you left the game with 2 levels before running again

#

?

round cairn
#

i joined the game with level 1, and i got to level2, and left

#

its supposed to save automatically no?

little gale
#

what did it print after you left with level 2

pastel cairn
round cairn
#

let me see

round cairn
pastel cairn
round cairn
#

after leaving with levle2

pastel cairn
#

i'd wager you're doing player:AddXP() on the client

little gale
#

your changing data on the client

#

most likely

pastel cairn
little gale
#

that screenshot says it all

pastel cairn
#

which the server doesnt know about

round cairn
round cairn
round cairn
little gale
little gale
#

💀

round cairn
#

how can i resolve this..

pastel cairn
fast spoke
#

first rule in testing data saving, dont change data in client

little gale
#

use a remote event to send a message to change data on the server

#

or re-write the system

pastel cairn
#

knowing the problem is one thing, fixing it is a whole different problem, specially in cases like this spanishkek

pastel cairn
round cairn
little gale
round cairn
#

oh wait

#

i have my XP/leveling on

#

local script

#

so i should make it local ye?

little gale
#

thats literally what we said

round cairn
#

script*

little gale
#

not to make it local

round cairn
#

yeah script **

pastel cairn
# round cairn playerdatasave?

frankly if you don't do it properly you're opening your game wide to exploiters. lol remoteevent.OnServerEvent:Connect(function(plr,item,cost) plr.Money-=cost plr:GiveItem(item) end) spanishkek

little gale
round cairn
round cairn
#

open world game

pastel cairn
little gale
#

because

pastel cairn
#

less than 1k visits, already first exploiter, and that's only the one that was caught

round cairn
little gale
#

well when there is one then someone will cheat to the end asap

pastel cairn
#

that's a 100% guaranteed confirmed exploiter btw, there ain't no false positives with the way that skid got banned hehe

round cairn
#

then he aint gonna get the experience of the game so idc abt him

little gale
blazing spruceBOT
#

studio** You are now Level 17! **studio

round cairn
#

the whole point is to go through a adventure, defeat bosses, side quests, so if he goes to end then no point?

little gale
#

people leave because of it

#

dead game

round cairn
#

right now its a small project/test

pastel cairn
round cairn
#

if it goes somewhat decent i will invest for scripters

little gale
pastel cairn
little gale
#

and by that point it will be too late

little gale
pastel cairn
round cairn
little gale
#

I guess

round cairn
#

if i hire rn, it can be a waste or success

little gale
little gale
round cairn
little gale
#

A. I already lead a team
B. You gave me a bad impression as a planner

round cairn
#

im literally trying and testing

#

and if my test goes good i will invest

little gale
round cairn
#

u want me to add super high end anticheat for my test game?

little gale
pastel cairn
# little gale https://tenor.com/view/movie-one-eternity-later-gif-7900643

it is a very fair idea to prioritize developing the actual game first. anticheat can come in at a close second. it's not uncommon for brand new games to completely reset player data (with consideration given to player robux purchases) so i mean if you state that somewhere people won't mind the exploiters until the game has an opportunity to first have that as a problem it needs to care about and then second have a chance to do something about it

pastel cairn
round cairn
#

but again even if cheaters ruin my game

#

it will ruin for a couple people

little gale
#

honestly just do what you think is best

round cairn
#

by that time i can hire scripers

#

so again about the uhm local script, how do i change it to a script?

little gale
#

trial and error is best

little gale
pastel cairn
round cairn
#

this is my uhh Xphandler is this the one?

#

although i have high hopes it will succeed

pastel cairn
#

awardXP should usually happen on server not client

round cairn
#

ah

#

guess chatgpt thought it was gonna be single player game

#

do i ask it to rewrite the local into a script, that isnt single player but rather multi or?

pastel cairn
round cairn
#

the brain capacity of my 2 braincells is too much to handle here

round cairn
#

like survival,open world etc

little gale
#

But I do have a tip in case your not doing so already: Learn a skill or 2 (Scripting, Builder, Gfx, Vfx, music, etc.) and practice practice practice. Dont overwhelm yourself learning a whole bunch of stuff all at once especially as a new aspiring dev

round cairn
little gale
#

I tried that once, burnout in the first 2 weeks

round cairn
#

to master a language can take a year or more

#

smth i dont plan on doing tbh

little gale
#

also if you have the option, find a friend that wants to make games so that you can help each other figure things out. The more the better

#

its always much more fun working with someone else

#

but its your choice still

pastel cairn
pastel cairn
# round cairn i mainly focus on building

i don't care much for builders since i can build myself, you'd have to have a very dashing portfolio that competes with other builders in #👷︱for-hire in your price range. if you had related building skills like modelling, texturing, csg, or non-humanoid animation, maybe i'd have work for you, but.. yea building can mean a lot of different things.

#

if your best work is a gas station, that isn't good enough for what i'm looking for

#

it's good, but i need more than a few days of tedium putting together a storefront

little gale
#

Welp ima head out, good luck on your journey

round cairn
#

but uhm i believe we are on wrong track, so could u help me out w the script?..

round cairn
#

so i gotta redo everything?..

pastel cairn
# round cairn guess chatgpt thought it was gonna be single player game

i mean let's be honest here you know nothing about coding, ai is doing all the heavy lifiting, so even if i told you how to solve it, you wouldn't even know where to start. chatgpt is doing it for you. that's why i say maybe try asking the person who wrote this code for you fingerguns we helped you with the problem, but if we just simply do it for you, that's not help anymore, that's just free labor hehe

round cairn
pastel cairn
round cairn
#

alright thanks for letting me know