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

Why won't this datastore script store data?

Asked by
Knqe 23
4 years ago

I'm not getting any errors from the script (I removed the pcalls to make sure) Can someone help me out?

local ds = game:GetService("DataStoreService"):GetDataStore("ds")

game.Players.PlayerAdded:Connect(function(plr)
    local key = "id-"..plr.UserId
    local Stats = Instance.new("Folder",plr)
    local Lvl = Instance.new("IntValue",Stats)
    local Exp = Instance.new("IntValue",Stats)
    local Exc = Instance.new("IntValue",Stats)
    local Pts = Instance.new("IntValue",Stats)
    local Arm = Instance.new("IntValue",Stats)
    local Dmg = Instance.new("IntValue",Stats)
    local Rei = Instance.new("IntValue",Stats)
    Stats.Name = "Stats"
    Lvl.Name = "Lvl"
    Exp.Name = "Exp"
    Exc.Name = "Exc"
    Pts.Name = "Pts"
    Arm.Name = "Arm"
    Dmg.Name = "Dmg"
    Rei.Name = "Rei"
    local info = ds:GetAsync(key)
    pcall(function()
        Lvl.Value = info[1]
        Exp.Value = info[2]
        Exc.Value = info[3]
        Pts.Value = info[4]
        Arm.Value = info[5]
        Dmg.Value = info[6]
        Rei.Value = info[7]
        if Lvl.Value == 0 then
            Lvl.Value = 1
        end
        if Exc.Value == 0 then
            Exc.Value = Lvl.Value * 5
        end
        end)

    while Exp.Value >= Exc.Value do
        Lvl.Value = Lvl.Value + 1
        Exp.Value = Exp.Value - Exc.Value
        Exc.Value = Lvl.Value * 5
    end
end)

game.Players.PlayerRemoving:Connect(function(plr)
    local key = "id-"..plr.UserId
    local info = {}
    local Stats = plr:WaitForChild("Stats")
    local Lvl = Stats:WaitForChild("Lvl")
    local Exp = Stats:WaitForChild("Exp")
    local Exc = Stats:WaitForChild("Exc")
    local Pts = Stats:WaitForChild("Pts")
    local Arm = Stats:WaitForChild("Arm")
    local Dmg = Stats:WaitForChild("Dmg")
    local Rei = Stats:WaitForChild("Rei")
        table.insert(info,Lvl.Value)
        table.insert(info,Exp.Value)
        table.insert(info,Exc.Value)
        table.insert(info,Pts.Value)
        table.insert(info,Arm.Value)
        table.insert(info,Dmg.Value)
        table.insert(info,Rei.Value)
    ds:SetAsync(key,info)
end)

1 answer

Log in to vote
0
Answered by
Knqe 23
4 years ago

Solved my own issue. I'm not sure what the problem was, but I changed a lot and fixed the issue.

0
Anyways don't use the second parameter for Instance.New. https://devforum.roblox.com/t/psa-dont-use-instance-new-with-parent-argument/30296 XviperIink 428 — 4y
Ad

Answer this question