Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Store data, but reset the data for the player?

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

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

1 comment

0

Please explain what you're doing. How will OP learn?

This discussion is preserved as it was. New answers, comments, and votes are closed.