#Datasave wont work

14 messages · Page 1 of 1 (latest)

rotund solar
#

My datasave wont work for some reason

#

help

#
local DataStoreService = game:GetService("DataStoreService")
local BucksDataStore = DataStoreService:GetDataStore("BucksDataStore")
local DefaultBucks = 0
local DefaultWins = 0
local playersLeft = 0

game.Players.PlayerAdded:Connect(function(player)
    playersLeft = playersLeft + 1

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

    local bucks = Instance.new("IntValue")
    bucks.Name = "Bucks"
    bucks.Value = DefaultBucks
    bucks.Parent = leaderstats

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


    player.CharacterAdded:Connect(function(character)
        if character and character:FindFirstChild("Humanoid") then
            local humanoid = character:WaitForChild("Humanoid")

            
            humanoid.Died:Connect(function()
                if character:FindFirstChild("GameTag") then
                    character.GameTag:Destroy()
                end
                player:LoadCharacter()
            end)
        end
    end)

    
    local playerDataBucks, playerDataWins

    pcall(function()
        playerDataBucks = BucksDataStore:GetAsync(player.UserId.."-Bucks")
        playerDataWins = BucksDataStore:GetAsync(player.UserId.."-Wins")
    end)

    if playerDataBucks then
        bucks.Value = playerDataBucks
    else
        bucks.Value = DefaultBucks
    end

    if playerDataWins then
        wins.Value = playerDataWins
    else
        wins.Value = DefaultWins
    end
end)

local bindableEvent = Instance.new("BindableEvent")

game.Players.PlayerRemoving:Connect(function(player)
    pcall(function()
        BucksDataStore:SetAsync(player.UserId.."-Bucks", player.leaderstats.Bucks.Value)
        BucksDataStore:SetAsync(player.UserId.."-Wins", player.leaderstats.Wins.Value)
        print("Saved")
        playersLeft = playersLeft - 1
        bindableEvent:Fire()
    end)
end)


lunar root
#

Advanced Roblox Scripting Tutorial #13 - Data Store / Saving Player Data (Beginner to Pro 2019)

Hey guys, i know i've been gone for a while and i apologize for that but I am back and in today's video i am going to be teaching you guys about data stores and how they work. Basically saving player data. Anyways this a very long tutorial which is m...

▶ Play video
rotund solar
lunar root
#

Uh

#

Is there any errors?

red oxideBOT
#

studio** You are now Level 8! **studio

rotund solar
#

npe

#

no

lunar root
#

IM not really good at scripting but I can send you mine and copy that it has multiple stats too

rotund solar
#

ok

lunar root
#
local mydss = dss:GetDataStore("mydss")



game.Players.PlayerAdded:Connect(function(Player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = Player

    local Cash = Instance.new("IntValue")
    Cash.Name = "Cash"
    Cash.Parent = leaderstats
    Cash.Value = 0
    
    local tiercount = Instance.new("IntValue", leaderstats)
    tiercount.Name = "Tiers"
    tiercount.Value = 0
    
    local playerUserId = "Player_"..Player.UserId
    --load
    local data
    local success, errormessage = pcall(function()
        data = mydss:GetAsync(playerUserId)
    end)
    if success then
        Cash.Value = data.Cash
        tiercount.Value = data.Tier
    end
    

    
    
    
    
    
    
    local asd = workspace.asd
    
    local gain = 1
    asd.uveg2.Touched:Connect(function(Player)
        Cash.Value = Cash.Value +gain
        if Cash.Value >= 10 then 
            Cash.Value = Cash.Value +gain
            tiercount.Value = 1
        end
        if Cash.Value >= 100 then 
            Cash.Value = Cash.Value +gain*2
            tiercount.Value = 2
        end
        if Cash.Value >= 250 then 
            Cash.Value = Cash.Value +gain*4 * tiercount.Value
            tiercount.Value = 3
            print(gain*2*tiercount.Value)
        end
        print((gain*2)*tiercount.Value)
    end)
end)

game.Players.PlayerRemoving:Connect(function(player)
    
    local playerUserid = "Player_"..player.UserId
    
    local data = {
        Cash = player.leaderstats.Cash.Value,
        Tier = player.leaderstats.Tiers.Value
    }
    
    local success, errormessage = pcall(function()
        mydss:SetAsync(playerUserid, data)
    end)
    if success then
        print("Success")
    else
        warn(errormessage)
        print("error")
    end
    
end)```
#

Ignore the rest