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

My data store is not working correctly for leaderstats?

Asked by 3 years ago
local DS = game:GetService("DataStoreService")
local myDataStore = DS:GetDataStore("myDataStore")

game.Players.PlayerAdded:Connect(function(plr)
    local leaderstats = Instance.new("Folder", plr)
    leaderstats.Name = "leaderstats"
    local Gems = Instance.new("IntValue")
    Gems.Value = 0 
    Gems.Name = "Gems"
    Gems.Parent = leaderstats


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




    local playeruserid = "Player"..plr.UserId
    print(playeruserid)
    -- LOAD DATA
    -- YEAH -- YEAH
    local data
    local succsess, errormessage = pcall(function()
     data = myDataStore:GetAsync(playeruserid)
    end) 
    if succsess then
        if data then
            Gems.Value = data.Gems
    end
        -- SET OUR DATA 
    end




    game.Players.PlayerRemoving:Connect(function(player)
        local playeruserid = "Player"..plr.UserId

        local data = {
            Gems = player.leaderstats.Gems.Value;
            Wins = player.leaderstats.Wins.Value;
        }
        local succsess, errormessage = pcall(function()
        myDataStore:SetAsync(playeruserid, data)
        end)

        if succsess then 
            print("finally")
        else
            print("nope you didn't wrong WARNING")
            warn(errormessage)
        end


    end)

end)

but then i get this Workspace.DATA STORE LEADERSTATS:31: attempt to index number with 'Gems'

Answer this question