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

I'm So Confused! My DataSaver Won't Work? It Doesn't Show Any Errors Either

Asked by 4 years ago

I've been trying for the past 30 minutes to get this to work,

it doesn't show any error code or anything

it just doesn't save the data.

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


game.Players.PlayerAdded:Connect(function(plr)

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

    local kills = Instance.new("IntValue")
    kills.Name = "Kills"    
    kills.Parent = stats

    local deaths = Instance.new("IntValue")
    deaths.Name = "Deaths"
    deaths.Parent = stats

    local data 
    local success, errormessage = pcall(function()
        data = ds:GetAsync(plr.UserId.."-kills")
    end)

    if success then
        kills.Value = data
    else
        print("There Was A Data Error")
        warn(errormessage) 
    end
    plr.CharacterAdded:connect(function(char)

        local humanoid

        repeat
            humanoid = char:FindFirstChild("Humanoid")
            wait()
        until humanoid

        humanoid.Died:connect(function()

            deaths.Value = deaths.Value + 1

            local tag = humanoid:FindFirstChild("creator")

            if tag then

                local killer = tag.Value

                if killer then

                    killer.leaderstats.Kills.Value = killer.leaderstats.Kills.Value + 1
                end
            end
        end)
    end)

end)

game.Players.PlayerRemoving:Connect(function(plr)


    local success, errormessage = pcall(function()
        ds:SetAsync(plr.UserId.."-kills",plr.leaderstats.Kills.Value)
    end)

    if success then
        print("Kills Saved!")
    else
        print("Data Saving Error")
        warn(errormessage)
    end

end)

Answer this question