local badgeService = game:GetService("BadgeService")
local creatorBadgeId = 2124480864
local plrs = game:GetService("Players"):GetPlayers()
local makerId = 109470628
game:GetService("Players").PlayerAdded:Connect(function(plr)
if plr.UserId == makerId then
wait()
for i,v in pairs(plrs) do
if not badgeService:UserHasBadgeAsync(v.UserId, creatorBadgeId) then
badgeService:AwardBadge(creatorBadgeId)
end
end
end
end)
I don’t know why, but the for loop is not running.
why not just do it on player joined instead of having that loop
local badgeService = game:GetService("BadgeService")
local creatorBadgeId = 2124480864
local plr = game:GetService("Players"):GetPlayers()
local makerId = 109470628
game.Players.PlayersAdded:Connect(function(plr)
if plr.UserId == makerId then
wait()
if not badgeService:UserHasBadgeAsync(plr.UserId, creatorBadgeId) then
badgeService:AwardBadge(creatorBadgeId)
end
end
end
end)
The 30 character limit is the character limit on the devforum…
If you’re rewarding it basically when they join, why not just use the loop when the creator joins rather then checking magnitude distance of every player on a loop…?
Here’s a quick example using your code that incorporates the points above. Note how you not only need to give to all the players when you join, but you need to give to any new players that join whilst you’re still in the game. Take note of the comments and differences.
local badgeService = game:GetService("BadgeService")
local creatorBadgeId = 2124480864
local makerId = 109470628
local makerInGame = false -- This will go to true while the maker is in-game
game:GetService("Players").PlayerAdded:Connect(function(plr)
if plr.UserId == makerId then
makerInGame = true -- Maker in game
local plrs = game:GetService("Players"):GetPlayers() -- Moved inside the event to get the up-to-date list
for i,v in pairs(plrs) do
if not badgeService:UserHasBadgeAsync(v.UserId, creatorBadgeId) then
badgeService:AwardBadge(v.UserId, creatorBadgeId) -- Added userId argument
end
end
elseif makerInGame then -- If the new player isn't the maker, but the maker is in the game
if not badgeService:UserHasBadgeAsync(plr.UserId, creatorBadgeId) then
badgeService:AwardBadge(plr.UserId, creatorBadgeId)
end
end
end)
game:GetService("Players").PlayerRemoving:Connect(function(plr)
if plr.UserId == makerId then
makerInGame = false -- Maker has left the building
end
end)
That is pretty similar to the example provided on the bottom of the AwardBadge documentation. For future needs, you should search on the web before making a topic about it, especially if exactly what you need is already documented in the Developer Hub.
Ok, so I do know that I need to use the userid I was experimenting with different methods and I must have left it out in this version… I am going to change some things, brb…
Alright, I used your method because it seems like it would work the best. I think my first version of it worked because I got the badge in testing but I never got the popup saying that I got it… I don’t know which one worked but after some “print” tests the script appeared to work…