I'm using DataStore.How would I make the value save to the player instead of server.Note: The Value is in the player and not a variable.
Actually, Data Store should be rather used to store player save data as it says in the Data Persistence Wiki itself. tldr; don't use Data Persistence for anything. (Except if you're saving Instances, like models and parts)
Data Persistence is a method of saving data for games so that the data can then be loaded when the player visits the game again. Data Stores were more recently introduced and are more robust than Data Persistence and are now the recommended method of storing player data.
This is something I wrote up in a few minutes, so forgive of the rustiness. Just tell me if there is anything wrong because I haven't tested it. xD
local ds = game:GetService("DataStoreService"):GetDataStore("Score") game.Players.PlayerAdded:connect(function(player) local key = "user_" .. player.userId local score = 0 ds:UpdateAsync(key, function(oldValue) local newValue = oldValue or 0 --oldValue might be nil score = newValue return newValue end) repeat wait() until player.Character local stat = Instance.new("IntValue") stat.Name = "leaderstats" local ls = Instance.new("Score") ls.Value = score ls.Parent = stat stat.Parent = player end) game.Players.PlayerRemoving:connect(function(player) local key = "user_" .. player.userId ds:UpdateAsync(key, function(oldValue) local newValue = player.leaderstats["Score"].Value return newValue end) end)
You would use Data Persistence, not data store to save to a player instead of the server. http://wiki.roblox.com/index.php?title=Data_persistence