You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Make it so when you meet the game developer you get a badge
What is the issue? It won’t award me the badge
What solutions have you tried so far? I tried putting the badge ID other places and changed some of the if statements from IF to if
Code:
local BadgeService = game:GetService("BadgeService")
local function awardBadge(plr, badgeId)
local success, badgeInfo = pcall(BadgeService.GetBadgeInfoAsync, BadgeService, badgeId)
if success then
if badgeInfo.IsEnabled then
local awarded, errorMessage = pcall(BadgeService.AwardBadge, BadgeService, plr.UserId, badgeId)
end
end
end
game.Players.PlayerAdded:Connect(function(plr)
for _,v in pairs(game.Players:GetPlayers()) do
if v:FindFirstChild("CTFD_services") then
awardBadge(2128736008)
end
end
end)
local ownerId = 69420 -- the owner's userid
local BadgeService = game:GetService("BadgeService")
local function awardBadge(plr, badgeId)
local success, badgeInfo = pcall(BadgeService.GetBadgeInfoAsync, BadgeService, badgeId)
if success then
if badgeInfo.IsEnabled then
local awarded, errorMessage = pcall(BadgeService.AwardBadge, BadgeService, plr.UserId, badgeId)
end
end
end
function init(plr)
for _,v in pairs(game.Players:GetPlayers()) do
if v.UserId = ownerId then
awardBadge(plr, 2128736008) -- you forgot to put the player on the first argument
break -- dont forgor to break
end
end
end
for i, v in next, game.Players:GetPlayers() do
init(v) -- catch previous players
end
game.Players.PlayerAdded:Connect(init)
i recommend using userids instead of finding an instance named “CFTD_services”. because i think your script will never find one even when the owner is in the server
game.Players.PlayerAdded:Connect(function(plr)
for _,v in pairs(game.Players:GetPlayers()) do
if v:FindFirstChild("CTFD_services") then
awardBadge(2128736008) -- Here
end
end
end)
Are you sure you’ve given me the full script? Line 8 on your original script is just an end (and all the parentheses are closed as far as I can tell), so it wouldn’t cause an error like that.
local BadgeService = game:GetService("BadgeService")
local function awardBadge(plr, badgeId)
local success, badgeInfo = pcall(BadgeService.GetBadgeInfoAsync, BadgeService, badgeId)
if success then
if badgeInfo.IsEnabled then
local awarded, errorMessage = pcall(BadgeService.AwardBadge, BadgeService, plr.UserId, badgeId)
end
end
end
game.Players.PlayerAdded:Connect(function(plr)
for _,v in pairs(game.Players:GetPlayers()) do
If v:FindFirstChild("Your Username") then
awardBadge(v, IdHere)
end
end
end)
Make sure to replace the uppercase “If” that you have with an “if”.
Other than that, make sure you don’t use v here:
game.Players.PlayerAdded:Connect(function(plr)
for _,v in pairs(game.Players:GetPlayers()) do
If v:FindFirstChild("Your Username") then -- Uppercase Ifs don't work
awardBadge(v, IdHere) -- This will only award the player with the found username
end
end
end)
Instead, do this:
game.Players.PlayerAdded:Connect(function(plr)
for _,v in pairs(game.Players:GetPlayers()) do
if v:FindFirstChild("Your Username") then
awardBadge(plr, IdHere)
end
end
end)
game.Players.PlayerAdded:Connect(function(plr)
for _,v in pairs(game.Players:GetPlayers()) do
if v:FindFirstChild("My Username") then
awardBadge(plr, badgeID)
end
end
end)
game.Players.PlayerAdded:Connect(function(plr)
for _,v in pairs(game.Players:GetPlayers()) do
if v:FindFirstChild("CTFD_services") then
awardBadge(plr, 2128736008)
end
end
end)