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

Store data, but reset the data for the player?

Asked by 6 years ago
Edited 6 years ago

I made a simple GlobalDataStore script but I'm wondering how I would go about making the saved leaderstat value behave normally as if it was saved, while resetting the data to zero for the player whenever they join? Heres my attempt at making the datastore script do the above:

local DataStore = game:GetService("DataStoreService"):GetDataStore("CoolDataStore")

local function Added(Player)
    local LS = Instance.new("Folder",Player)
    LS.Name = "leaderstats"

    local Stage = Instance.new("NumberValue", LS)
    Stage.Name = "Points"
end

game.Players.PlayerRemoving:Connect(function(Player)
    Data:SetAsync(Player.UserId, Player.leaderstats.Point.Value)
end)

game.Players.PlayerAdded:Connect(Added)

Help would be much appreciated, thanks!

1 answer

Log in to vote
-1
Answered by 6 years ago

Here's the working version. :D

local DataStore = game:GetService("DataStoreService"):GetDataStore("CoolDataStore")

local function Added(Player)
    local LS = Instance.new("Folder",Player)
    LS.Name = "leaderstats"

    local Stage = Instance.new("NumberValue", LS)
    Stage.Name = "Points"
    Stage.Value = DataStore:GetAsync(Player.userId)

    Stage.Changed:connect(function()
        wait(0.2)
        DataStore:SetAsync(Player.userId, Stage.Value)
    end)

end

game.Players.PlayerAdded:Connect(Added)

Hope this helped. <3

0
Please explain what you're doing. How will OP learn? User#19524 175 — 6y
Ad

Answer this question