I’m Jonah and I’m going to teach you how to create a script that detects if the creator is in the player’s server and then award them a badge!
First, we need BadgeService. This will let us award badges to players.
local badgeService = game:GetService("BadgeService")
Second, we will create two variables to store the badge’s ID and the creator’s username.
local badgeService = game:GetService("BadgeService")
local badgeId = 0
local creatorUsername = ""
Third, we need to detect when a player joins your game.
local badgeService = game:GetService("BadgeService")
local badgeId = 0
local creatorUsername = ""
game.Players.PlayerAdded:Connect(function(player)
end)
Fourth, we will use an if statement to check if the player’s name is equal to the creator’s name, and if it is, we will use a for loop to award a badge to every player in the server.
local badgeService = game:GetService("BadgeService")
local badgeId = 0
local creatorUsername = ""
game.Players.PlayerAdded:Connect(function(player)
if player.Name == creatorUsername then
for _, v in pairs(game.Players:GetPlayers()) do
badgeService:AwardBadge(v.UserId, badgeId)
end
end
end)
If a player joins when the creator is already in the server, no badge will be awarded to them. We can fix this by searching the player list for the creator’s name and if we find a match, we will award the badge to only the player who joined.
local badgeService = game:GetService("BadgeService")
local badgeId = 0
local creatorUsername = ""
game.Players.PlayerAdded:Connect(function(player)
if player.Name == creatorUsername then
for _, v in pairs(game.Players:GetPlayers()) do
badgeService:AwardBadge(v.UserId, badgeId)
end
end
if game.Players:FindFirstChild(creatorUsername) then
badgeService:AwardBadge(player.UserId, badgeId)
end
end)
Now you have a working “Met the Creator” badge giver!