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!
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