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

[SOLVED] Why is this DataStore code not working? It seems like the same as the video.

Asked by 1 year ago
Edited by Xapelize 1 year ago

This question has been solved by the original poster.

Leaderstats saving and loading from AlvinBlox

game.Players.PlayerAdded:Connect(function(player)

    --leaderstats variables
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player


    local Sips = Instance.new("IntValue")
    Sips.Name = "Sips"

    --load function with pcall
    local success, value = pcall(function()
        return myData:GetAsync(player.UserId)
    end)

    if success then
        Sips.Value = value
        print("Data was loaded successfully")
    end

    Sips.Parent = leaderstats

end)

--save data function
game.Players.PlayerRemoving:Connect(function(player)

    local success, errormessage = pcall(function()
        myData:SetAsync(player.UserId, player.leaderstats.Sips.Value)
    end)

    if success then
        print("Data was saved successfull!")
    else
        print("There was an error when saving data!")
        warn(errormessage)
    end

end)
0
Are you sure API and Third-Party Services are on? T3_MasterGamer 2189 — 1y
0
The problem was that I didn't write the myData variable. Thanks itsmtninja 11 — 1y

Answer this question