So I have this very simple GUI where you can type a code and if you type the correct code you are awarded a badge, but I want to choose the number of people that are able to get this code “So for example, only 1 person can redeem this code (and they will get the badge for redeeming it first), and then anyone that tries to redeem it after that 1st person already redeemed it, won’t get the badge”.
How do I make that work? (I wanted to make it so that its global, as in the first person in all servers, as the code is a 1-time use only and then it expires forever)
Here is what the GUI looks like:
Frame2 is basically what shows if you enter the correct code:
This is how the local script currently looks like:
local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
local BADGE_ID = 2146480330
script.Parent.MouseButton1Click:Connect(function()
if script.Parent.Parent.TextBox.Text == "JD93CGKG" then
script.Parent.Parent.Parent.Frame2.Visible = true
local function awardBadge(player, badgeId)
-- Fetch badge information
local success, badgeInfo = pcall(function()
return BadgeService:GetBadgeInfoAsync(badgeId)
end)
if success then
-- Confirm that badge can be awarded
if badgeInfo.IsEnabled then
-- Award badge
local awardSuccess, result = pcall(function()
return BadgeService:AwardBadge(player.UserId, badgeId)
end)
if not awardSuccess then
-- the AwardBadge function threw an error
warn("Error while awarding badge:", result)
elseif not result then
-- the AwardBadge function did not award a badge
warn("Failed to award badge.")
end
end
else
warn("Error while fetching badge info: " .. badgeInfo)
end
end
local function onPlayerAdded(player)
awardBadge(player, BADGE_ID)
end
Players.PlayerAdded:Connect(onPlayerAdded)
end
end)
(As seen in the LocalScript, the code, in this case, is “JD93CGKG”)