Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why would my dataStore not load my game data?

Asked by
R3M_1 11
2 years ago
Edited 2 years ago

I'm not for sure if it's not saving or not loading, due to the fact i have a pcall set up and it runs save successful and loading successful. It's a super simple script, and I have Api services turned on Aswell! I'm new to Datastore services, and I've done research on a ton of datastores setup multiple ways, but none seem to work for me!!

Current leaderstats\DataSaving Script

local player = game:GetService('Players')
local dss = game:GetService("DataStoreService")
local dataStore = dss:GetDataStore("clickData")

player.PlayerAdded:Connect(function(plr)
    print(plr.Name..plr.UserId.." Has Been Added to the Game")

    local leaderstats = Instance.new("Folder",plr)
    leaderstats.Name = "leaderstats"
    local clicks = Instance.new("IntValue", leaderstats)
    clicks.Name = "Clicks"
    clicks.Value = 0

    local data

    local succ, err = pcall(function()
            data = dataStore:GetAsync( "player_"..plr.UserId)
    end)

    if succ then
        print("DataLoaded!")
        clicks.Value = data
    else
        print("DataNotSaved")
        warn(err)
    end






end)

player.PlayerRemoving:Connect(function(plr)
    local data 

    local succ, err = pcall(function()
            data = dataStore:SetAsync( "player_"..plr.UserId, plr.leaderstats.Clicks.Value)
    end)

    if succ then
        print("DataSaved")
    else
        print("SaveFailed")
        warn(err)
    end
end)

Previous Script

local player = game:GetService('Players')
local dss = game:GetService("DataStoreService")
local dataStore = dss:GetDataStore("clickData")

player.PlayerAdded:Connect(function(plr)
    print(plr.Name..plr.UserId.." Has Been Added to the Game")

    local leaderstats = Instance.new("Folder",plr)
    leaderstats.Name = "leaderstats"
    local clicks = Instance.new("IntValue", leaderstats)
    clicks.Name = "Clicks"
    clicks.Value = 0

    local data

    local plrid = plr.UserId



    local succ, err = pcall(function()
        data = dataStore:GetAsync( "player_"..plrid)
    end)

    if succ then
        print("DataLoaded!")
        clicks.Value = data
    else
        print("DataNotSaved")
        warn(err)
    end






end)

player.PlayerRemoving:Connect(function(plr)
    local data

    local plrid = plr.UserId

    local succ, err = pcall(function()
        data = dataStore:SetAsync( "player_"..plrid, plr.leaderstats.Clicks.Value)
    end)

    if succ then
        print("DataSaved")
    else
        print("SaveFailed")
        warn(err)
    end
end)

0
Does the error print? LeoPlaysGames_RBX 26 — 2y
0
no error prints, the only thing that prints are data loaded and data save R3M_1 11 — 2y

1 answer

Log in to vote
0
Answered by
Puppynniko 1059 Moderation Voter
2 years ago

Change PlrId_fordata to "player_"..plrid idk why but that fixes it

0
I redone the script, if i understood what you meant correctly, and it's still not loading my player data. I Put on updated script with what i thought you meant R3M_1 11 — 2y
0
i meant dont do it with a variable it does not work for some reason Puppynniko 1059 — 2y
0
ive changed it from a variable and it still isnt working, it comes up with no error but doesnt actually load the stats to the leaderboard. R3M_1 11 — 2y
0
thats strange it was working for me did you turn on api services Puppynniko 1059 — 2y
View all comments (3 more)
0
I do have Api services on R3M_1 11 — 2y
0
is this script inside of serverscriptservices Puppynniko 1059 — 2y
0
it was, but still didnt work, i swapped to DataStore2 and it worked like a charm! Thank you for the problem solving up till now! R3M_1 11 — 2y
Ad

Answer this question