How do I make a transfer leaderstats command?
I would like to be able to transfer leaderstats from one person to another. For example the person could be able to type in chat: /transfer coins(leaderstat value) H34E7R(the player they're sending it to) 1000(amount).
I will send my leaderstat script.
01 | local currencyName = "Coins" |
02 | local DataStore = game:GetService( "DataStoreService" ):GetDataStore( "TestDataStore" ) |
03 | game.Players.PlayerAdded:Connect( function (player) |
05 | local folder = Instance.new( "Folder" ) |
06 | folder.Name = "leaderstats" |
07 | folder.Parent = player |
09 | local currency = Instance.new( "IntValue" ) |
10 | currency.Name = currencyName |
11 | currency.Parent = folder |
13 | local ID = currencyName.. "-" ..player.UserId |
17 | savedData = DataStore:GetAsync(ID) |
20 | if savedData ~ = nil then |
21 | currency.Value = savedData |
29 | game.Players.PlayerRemoving:Connect( function (player) |
30 | local ID = currencyName.. "-" ..player.UserId |
31 | DataStore:SetAsync(ID,player.leaderstats [ currencyName ] .Value) |
34 | game:BindToClose( function () |
35 | for i, player in pairs (game.Players:GetPlayers()) do |
37 | player:Kick( "This game is shutting down" ) |