Whenever the player clicks the checkmark, you could have a remote event that fires from client to server, telling the server to store the player nametag. It could be something like:
On the client side:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage.RemoteEvent
if BadgeService:UserHasBadgeAsync(UserId, BadgeId) then
LockBn.Image = "rbxassetid://17479511743"
LockBn.MouseButton1Click:Connect(function()
if LockBn.ImageColor3 ~= Color3.fromRGB(0, 185, 0) then
--Tells server which nametag it is, and if the nametag was equipped
RemoteEvent:FireServer(LockBn.Parent.Name, true)
else
RemoteEvent:FireServer(LockBn.Parent.Name, false)
end
end)
end
On a server script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage.RemoteEvent
local DataStoreService = game:GetService("DataStoreService")
local nametagStore = DataStoreService:GetDataStore("PlayerNametag") --create/access a datastore
RemoteEvent.OnServerEvent:Connect(function(player, nametag, equipped)
local success, currentGold = pcall(function()
if equipped then
--Store the nametag, for the key name, I'd use the player's user id since it is unique
nametagStore:SetAsync(tostring(player.UserId, nametag))
else
nametagStore:SetAsync(tostring(player.UserId, ""))
end
end)
if not success then
print(errorMessage)
end
end)
I would also recommend having a module script or a table to store the prefix text of the nametag for easier access; when a player joins the game, you can use datastore:GetAsync(keyname) to retrieve the player’s nametag, and get the prefix text by looking up the module script/table with the nametag, and then use the remote event to fire back to client to change the nametag.
For more information about data stores:
Data Stores | Documentation - Roblox Creator Hub