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

Why is DataStore2 not working after I tested?(Please help)

Asked by
naturedat 124
3 years ago
Edited 3 years ago

Hi, I'm trying to learn how to use datastore 2, this is what I got and whenever I play and rejoin, it doesn't save. I can't test it on the studio as there is already a player in the Players section. So there wouldn't be any player added. Also, is it just me are is everyone having a new icon in the explorer name CorePackages that can't be deleted?

local DataStore2 = require(1936396537)
DataStore2.Combine("MasterKey", "Kills", "Deaths", "Coins")
game.Players.PlayerAdded:Connect(function(plr)
    local datakill = DataStore2("Kills", plr)
    local datadeath = DataStore2("Deaths", plr)
    local datacoin = DataStore2("Coins", plr)
    -- leaderboard
    local stats = Instance.new("Folder")
    stats.Name = "leaderstats"
    stats.Parent = plr

    local kills = Instance.new("IntValue")
    kills.Name = "Kills"
    kills.Parent = stats
    kills.Value = datakill:Get(0)

    local deaths = Instance.new("IntValue")
    deaths.Name = "Deaths"
    deaths.Parent = stats
    deaths.Value = datadeath:Get(0)

    local coin = Instance.new("IntValue")
    coin.Name = "Coins"
    coin.Parent = stats
    coin.Value = datacoin:Get(0)

    -- Save Kills
    datakill.Changed:Connect(function()
        datakill:Set(kills.Value)
    end)
    -- Save Deaths
    datadeath.Changed:Connect(function()
        datadeath:Set(deaths.Value)
    end)
    --Save Drachmas
    datacoin.Changed:Connect(function()
        datacoin:Set(coin.Value)
    end)


    -- On death event
    plr.CharacterAdded:Connect(function(char)
        local humanoid = char:FindFirstChild("Humanoid")
        humanoid.Died:Connect(function()
            deaths.Value = deaths.Value + 1
        end)
    end)
end)

Help please, Thank you!

0
Shouldn't it save by players id? local datacoin = DataStore2("Coins", plr.UserId)? DavidMind67 -8 — 3y
0
Or you haven't turned on Allow HTTP Request? DavidMind67 -8 — 3y
0
hm, sure, let me try that naturedat 124 — 3y
0
Urgh, the datastore script isn't even working on the studio, the leaderboard didn't even appeared naturedat 124 — 3y
0
The script looks fine, problem is somewhere else. Maybe some rouge plugins? sleazel 1287 — 3y

1 answer

Log in to vote
1
Answered by 3 years ago

This doesnt work because you are using require by the ID please read the documentation for that

https://devforum.roblox.com/t/how-to-use-datastore2-data-store-caching-and-data-loss-prevention/136317

also you are increasing every value by a plus not the :Increment() Function here is a thread in the DevForums which shows a basic solution for your question

https://devforum.roblox.com/t/not-showing-leaderstats-when-using-datastore2/399573/17

0
but didn't they said that we should use require to keep it up to date? But I did try the other option. Thanks naturedat 124 — 3y
Ad

Answer this question