So I am making a mod panel and one of the options I am making is a refund system so you can type the player’s name in and how much you want to add to their leaderstats. This is my script:
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("Stats")
local Players = game:GetService("Players")
local cache = {}
function getUserIdFromUsername(name)
if cache[name] then return cache[name] end
local player = Players:FindFirstChild(name)
if player then
cache[name] = player.UserId
return player.UserId
end
local id
pcall(function ()
id = Players:GetUserIdFromNameAsync(name)
end)
cache[name] = id
return id
end
local Amount = script.Parent.Parent.Parent.Amount.TextBox.Text --fixed this line
local Player = script.Parent.Parent.Parent.Player.TextBox.Text --fixed this line
local PlayerId = getUserIdFromUsername(Player)
script.Parent.MouseButton1Click:connect(function()
DataStore:SetAsync(PlayerId, {
--["Points"] = Player.leaderstats.Points.Value + 1;
["Wins"] = Player.leaderstats.Wins.Value + Amount;
})
end)