I want to make a "You met the owner" badge [SOLVED]

  1. What do you want to achieve? I want to make a “You met the owner” badge.

  2. What is the issue? I’m a noob dev so idk how

  3. What solutions have you tried so far? I tried some free models (ofc I did what they wrote in the script)

Any help is appreciated! Sorry for the derangment!

Sorry if i do grammaticals errors, I’m french…

4 Likes

Theres many youtube tutorials on how to do it.

2 Likes

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

3 Likes

Thanks @CZXPEK and @Qin2007 for the help! I’ll try your ways! Hope it’ll work!

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)
1 Like

Thanks for feedback @PiercedMissile ! But I’ll try all theses solutions only tomorrow because actually I just can’t.

Sorry I’m very late but I tried to add this script into my game, but when I played with my brother he didn’t get the badge… Do you know why?

Is the script in ServerScriptService ?

I put A capital P in player, try this

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)

I’ll try that. Thanks! Have a good day!

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)
2 Likes

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!

2 Likes

Thanks for helping even if I think now I know how to do! Have a good day!

Sorry for the late answer. I tried the script and a few people (06) joined me and not any of them got the badge. So the script doesn’t work :slightly_frowning_face:

I think I know why it didn’t worked… That’s just because I’m idiot I put the script in Workspace but it should be in ServerScriptService…

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!

1 Like

I would suggest breaking your loop, if ownerid was found.

1 Like

Why would a break be necessary for this?

1 Like

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.

1 Like

I don’t think it’s relevant to break the loop after the conditional statement given that the for loop needs to be active each time a player joins.

Lets take this to PMs, so we don’t clog the thread.

1 Like