Still have questions? Join our Discord server and get real time help.
Log in to vote

[SOLVED] My DataStore script isn't working and there are no errors?

Asked by
Sorukan 202 Moderation Voter
5 months ago
Edited 5 months ago

The output doesn't print any error, it's just that it never saves or loads the data because it always prints "New Player". I have the Studio Access to API Services enabled and i did publish the game so i can't see what's wrong.

local dataStore = game:GetService('DataStoreService'):GetDataStore('DataStoreName') 

local currencyName = 'Gold'

    local folder ='Folder')
    folder.Name = 'leaderstats' 
    folder.Parent = player

    local currency ='IntValue')
    currency.Name = currencyName 
    currency.Parent = folder

    local ID = currencyName..'-'..player.UserId 
    local savedData = nil 

        local savedData = dataStore:GetAsync(ID)

    --//If player has data then load it
    if savedData ~= nil then
        currency.Value = savedData
        print('Data Loaded')
        --//Else if player doesn't have data then give them 500 Gold
        currency.Value = 500
        print('New Player')
why do you need to wrap :GetAsync() in a pcall User#23365 -5 — 5mo
Well according to a video that i saw, it is used to prevent the script from breaking entirely if an error occurs. Sorukan 202 — 5mo
pcall will return the error for you. first it returns false, and then a message with what the error is. take a look here >> GoodCallMrOlsen 55 — 5mo
I removed the pcall function and it worked, i'm still not sure why the person in the video i watched used the pcall function, it worked for him though. Sorukan 202 — 5mo

Answer this question