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

Why is my Level datastore saving the same as other leaderstats?

Asked by 6 years ago
Edited 6 years ago
local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("CashSaveSystem")
local ds1 = DataStore:GetDataStore("CashSaveSystem")

game.Players.PlayerAdded:connect(function(player)
    local stats = Instance.new('IntValue', player)
    stats.Name = 'leaderstats'

    local points = Instance.new('IntValue', stats)
    points.Name = 'Money'
    points.Value = ds:GetAsync(player.UserId) or 0
    ds:SetAsync(player.UserId, points.Value)
    points.Changed:connect(function()
        ds:SetAsync(player.UserId, points.Value)
    end)
    game.Players.PlayerRemoving:connect(function(player)
        ds:SetAsync(player.UserId, points.Value)
    end)

    local level = Instance.new('IntValue', stats)
    level.Name = 'Level'
    level.Value = ds1:GetAsync(player.UserId) or 0
    ds1:SetAsync(player.UserId, level.Value)
    level.Changed:connect(function()
        ds1:SetAsync(player.UserId, level.Value)
    end)
    game.Players.PlayerRemoving:connect(function(player)
        ds1:SetAsync(player.UserId, level.Value)
    end)



    player.CharacterAdded:connect(function(character)
        character:WaitForChild("Humanoid").Died:connect(function()
            local tag = character.Humanoid:FindFirstChild("creator")
            if tag ~= nil then
                if tag.Value ~= nil then
                    points.Value = points.Value + 0
                    level.Value = level.Value + 0
                    if character.Humanoid:FindFirstChild('creator') then
                        local Killer = character.Humanoid.creator.Value
                        Killer.leaderstats.Money.Value = Killer.leaderstats.Money.Value + 2
                        Killer.leaderstats.Level.Value = Killer.leaderstats.Level.Value + 0.1
                    end
                end
            end
        end)
    end)
end)


I am trying to make it so that when you kill someone your level goes up by 0.1, but it's not working, and I think it is saving the 'Level' leaderstat with the same as the money, because the save is saveing and loading my level as the same as my money. I have an item thet you need to be a certain level for, and that is not working either because of this.

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago
local ds = DataStore:GetDataStore("CashSaveSystem")
local ds1 = DataStore:GetDataStore("CashSaveSystem")

Your ds and ds1 are the same datastores (CashSaveSystem), that's probably what causes problems. Change the name of the second datastore and it should work.

0
That's what I had guessed, but I don't know what to change it to. Do you? FirestormFury 7 — 6y
Ad

Answer this question