there was a script for that on developer.roblox , now that they moved to create.roblox they probably have it removed
ownerid = 0 -- put owner id here
badgeId = 0 -- put badge id herw
game.Players.PlayerAdded:Connect(function(player)
if player.UserId == ownerid then
for i,v in ipairs(game.Players:GetPlayers()) do
game:GetService('BadgeService'):AwardBadge(v.UserId,badgeId)
task.wait()
end
end
end)
my version (of what i can remember) is extreemly simplified and untested
That would only work if the Player was in the game, THEN the owner joined. I believe this would work.
local ownerid = 0 -- put owner id here
local badgeId = 0 -- put badge id here
game.Players.PlayerAdded:Connect(function(player)
for i, child in ipairs(game.Players:GetPlayers()) do--gets all players
if child.UserId == ownerid then --if the owner is in the game...
game:GetService('BadgeService'):AwardBadge(Player,badgeId)--Award the badge to the new player
end
end
end)
local ownerid = 0 -- put owner id here
local badgeId = 0 -- put badge id here
game.Players.PlayerAdded:Connect(function(Player)
for i, child in ipairs(game.Players:GetPlayers()) do--gets all players
if child.UserId == ownerid then --if the owner is in the game...
game:GetService('BadgeService'):AwardBadge(Player,badgeId)--Award the badge to the new player
end
end
end)
They are both correct, you just need to combine them.
@Qin2007 will handle if the player was already in the game, then the owner joined. @PiercedMissile will handle if the owner was already in the game, then the player joined.
So simply combine them and check if the player being added is the owner or a player:
local ownerid = 0 -- put owner id here
local badgeId = 0 -- put badge id here
game.Players.PlayerAdded:Connect(function(player)
if player.UserId == ownerid then --if the owner joined the game
for i, child in pairs(game.Players:GetPlayers()) do
game:GetService('BadgeService'):AwardBadge(child.UserId,badgeId) --Award badges to all players
task.wait()
end
else
for i, child in pairs(game.Players:GetPlayers()) do--gets all players
if child.UserId == ownerid then --if the owner is in the game...
game:GetService('BadgeService'):AwardBadge(player,badgeId) --Award the badge to the new player
end
end
end
end)
Are you sure? When I joined my brother using @PiercedMissile’s script, he didn’t get the badge and when he joined me, don’t work too… But I think I know why it didn’t worked.
local BadgeId = 000000 -- Your BadgeId
local OwnerId = 000000 -- The Owner's UserId; probably yours.
game:GetService('Players').PlayerAdded:Connect(function(Player)
if Player.UserId == OwnerId then
for Index, InGamePlayer in ipairs(game:GetService('Players'):GetPlayers()) do
local Success, Error = pcall(function()
if InGamePlayer.UserId ~= OwnerId and not game:GetService('BadgeService'):UserHasBadgeAsync(InGamePlayer.UserId, BadgeId) then
game:GetService('BadgeService'):AwardBadge(InGamePlayer.UserId, BadgeId)
end
end)
if not Success and InGamePlayer.UserId ~= OwnerID then
pcall(function()
repeat game:GetService('BadgeService'):AwardBadge(InGamePlayer.UserId, BadgeId) until game:GetService('BadgeService'):UserHasBadgeAsync(InGamePlayer.UserId, BadgeId)
end)
end
end
end)
That should always work.
However, when I have time, I’ll update it so it will work if you’re in-game and the player joins, it will also award the badge to them; I’ll mention you when I do so!
Create a script in ServerScriptService and paste this:
local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
local ownerId = 0000000 -- Owner UserId
local badgeId = 0000000 -- Badge is here
local function awardBadge(plr, badgeId)
local success, badgeInfo = pcall(BadgeService.GetBadgeInfoAsync, BadgeService, badgeId)
if success then
if badgeInfo.IsEnabled then -- Check if the badge is enabled
local awarded, errorMessage = pcall(BadgeService.AwardBadge, BadgeService, plr.UserId, badgeId)
print(awarded,errorMessage)
end
end
end
Players.PlayerAdded:Connect(function(plr)
for _, player in pairs(Players:GetPlayers()) do
if player.UserId == ownerId then
awardBadge(plr, badgeId)
end
end
end)
If you want a more detailed explanation on how the script works, let me know. I hope this helped!
There is no need to loop through more players, if you have already figured out that owner is present
Edit: Also your script does not take into account, for when players already plays the game, and the owner joins. I’m sure the currently playing players should get the badge aswell.