I'm back with a new video where no scripting is required!!
Script:
local Players = game:GetService("Players")
local BadgeService = game:GetService("BadgeService")
-- IMPORTANT: Replace 0 with your actual "Meet the Owner" Badge ID
local MEET_THE_OWNER_BADGE_ID = 1080484959942023 -- CHANGE THIS TO YOUR BADGE ID
-- For group-owned games, you MUST set this to the specific UserId of the person considered "the owner".
local OWNER_USER_ID = 2803885095s -- !!! CHANGE THIS TO THE OWNER'S USERID !!!
local function tryAwardBadge(playerToReceive)
if MEET_THE_OWNER_BADGE_ID == 0 then
warn("MeetTheOwnerBadgeAwarder: MEET_THE_OWNER_BADGE_ID is not set. Badge will not be awarded.")
return
end
if OWNER_USER_ID == 0 then
warn("MeetTheOwnerBadgeAwarder: OWNER_USER_ID is not set. Badge will not be awarded.")
return
end
if not playerToReceive or not playerToReceive:IsA("Player") then
return
end
-- Don't award to the owner themselves for meeting themselves
if playerToReceive.UserId == OWNER_USER_ID then
return
end
local hasBadge = false
local successQuery, resultQuery = pcall(function()
hasBadge = BadgeService:UserHasBadgeAsync(playerToReceive.UserId, MEET_THE_OWNER_BADGE_ID)
end)
if not successQuery then
warn("MeetTheOwnerBadgeAwarder: Error checking if player " .. playerToReceive.Name .. " has badge: " .. tostring(resultQuery))
return -- Don't proceed if we can't check existing badges
end
if hasBadge then
-- Player already has the badge, no need to print unless debugging
-- print("MeetTheOwnerBadgeAwarder: Player " .. playerToReceive.Name .. " already has the badge.")
return
end
-- Award the badge
local successAward, resultAward = pcall(function()
return BadgeService:AwardBadge(playerToReceive.UserId, MEET_THE_OWNER_BADGE_ID)
end)
if successAward then
if resultAward then -- AwardBadge returns true on successful award
print("MeetTheOwnerBadgeAwarder: Successfully awarded 'Meet the Owner' badge (ID: " .. MEET_THE_OWNER_BADGE_ID .. ") to " .. playerToReceive.Name .. " (ID: " .. playerToReceive.UserId .. ")")
else
-- This case might occur if AwardBadge itself indicates a non-error failure.
-- print("MeetTheOwnerBadgeAwarder: BadgeService:AwardBadge returned false for " .. playerToReceive.Name .. ". Badge might not have been awarded.")
end
else
warn("MeetTheOwnerBadgeAwarder: Error awarding badge to " .. playerToReceive.Name .. ": " .. tostring(resultAward))
end
end
-- Function to check if the designated owner is in the game
local function isOwnerInGame()
if OWNER_USER_ID == 0 then return false end -- Owner not configured
for _, p in Players:GetPlayers() do
if p.UserId == OWNER_USER_ID then
return true
end
end
return false
end
-- Function to award the badge to all non-owner players if the owner is present
local function awardToPlayersIfOwnerPresent()
if not isOwnerInGame() then
return
end
for _, p in Players:GetPlayers() do
if p.UserId ~= OWNER_USER_ID then -- Don't award to the owner
tryAwardBadge(p)
end
end
end
-- Handle new players joining
local function onPlayerAdded(newPlayer)
if OWNER_USER_ID == 0 or MEET_THE_OWNER_BADGE_ID == 0 then
-- Configuration missing, do nothing further for this player join
return
end
if newPlayer.UserId == OWNER_USER_ID then
-- The Owner has joined. Award the badge to all other players currently in the server.
print("MeetTheOwnerBadgeAwarder: Owner (" .. newPlayer.Name .. ", ID: " .. newPlayer.UserId .. ") has joined. Checking other players for badge award.")
awardToPlayersIfOwnerPresent()
else
-- A non-owner player has joined. Check if the owner is already in the game.
if isOwnerInGame() then
print("MeetTheOwnerBadgeAwarder: Player " .. newPlayer.Name .. " (ID: " .. newPlayer.UserId .. ") joined while owner (ID: " .. OWNER_USER_ID .. ") is in game. Attempting badge award.")
tryAwardBadge(newPlayer)
end
end
end
if OWNER_USER_ID ~= 0 and MEET_THE_OWNER_BADGE_ID ~= 0 then
print("MeetTheOwnerBadgeAwarder: Script started. Checking for owner and existing players...")
awardToPlayersIfOwnerPresent()
else
if OWNER_USER_ID == 0 then
warn("MeetTheOwnerBadgeAwarder: CRITICAL - OWNER_USER_ID is not set (is 0). Please edit the script and provide the owner's UserId for the badge to work.")
end
if MEET_THE_OWNER_BADGE_ID == 0 then
warn("MeetTheOwnerBadgeAwarder: CRITICAL - MEET_THE_OWNER_BADGE_ID is not set (is 0). Please edit the script and provide the badge ID for the badge to work.")
end
end
Players.PlayerAdded:Connect(onPlayerAdded)
Tags (Ignore):
#roblox #robloxstudio #growagarden #badge