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 79
6 days ago
Edited 6 days 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 EXpodo1234ALT 1321 — 6d
Well according to a video that i saw, it is used to prevent the script from breaking entirely if an error occurs. Sorukan 79 — 6d
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 14 — 6d
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 79 — 6d

Answer this question