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.
local currencyName = "Coins"
local DataStore = game:GetService("DataStoreService"):GetDataStore("TestDataStore")
game.Players.PlayerAdded:Connect(function(player)
local folder = Instance.new("Folder")
folder.Name = "leaderstats"
folder.Parent = player
local currency = Instance.new("IntValue")
currency.Name = currencyName
currency.Parent = folder
local ID = currencyName.."-"..player.UserId
local savedData = nil
pcall(function()
savedData = DataStore:GetAsync(ID)
end)
if savedData ~= nil then
currency.Value = savedData
print("data loaded")
else
currency.Value = 50
print("new player")
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local ID = currencyName.."-"..player.UserId
DataStore:SetAsync(ID,player.leaderstats[currencyName].Value)
end)
game:BindToClose(function()
for i, player in pairs(game.Players:GetPlayers()) do
if player then
player:Kick("This game is shutting down")
end
end
wait(5)
end)

1 comment
https://www.robloxdev.com/api-reference/event/Player/Chatted https://www.robloxdev.com/articles/Lua-Libraries/string