Ad
Log in to vote
0

Badge for meeting a player?

Asked by 1 month ago
Edited 1 month ago

I've created a "you met the owner" badge and it works for me as I am the owner, however I would like to create another badge that is awarded for meeting another player i.e. a YouTuber. I'm not sure why my code isn't working.

local Id =2126366798

game.Players.PlayerAdded:Connect(function(Player)
    if game.Players:FindFirstChild("Kawaii_Haruhi25") then 
        for i, players in pairs(game.Players:GetPlayers())do 
            game.BadgeService:AwardBadge(players.UserId, Id)
        end
    end
end)
0
Are you 100% certain you've already tried changing the Badge ID and the Player username within the if statement to the ones you wanted? MrOctoFoam 0 — 1mo
0
Use GetPlayerByUserId. Usernames are subject to change. Ziffixture 6863 — 1mo

1 answer

Log in to vote
0
Answered by
MattVSNNL 378 Moderation Voter
1 month ago

The way you are identifying if the player is you is pretty bad!

You are looking for your name, if you change your name the code will not identify you as the owner!

I cooked up a better code for you, hope this helps! If it does, I'd be very happy if you accept my answer!

It's a code in ServerScriptService by the way as a Normal Script

local PlayersService = game:GetService("Players")
local BadgeService = game:GetService("BadgeService")

local playerId = 512412123 -- Put your userid here!
local badgeId = 35234234 -- Put badge id here!

PlayersService.PlayerAdded:Connect(function(player)
    if player.UserId == playerId then
        for _, player in pairs(PlayersService:GetPlayers()) do
            if player then

                BadgeService:AwardBadge(player.UserId, badgeId)

            end
        end
    end
end)
0
it works! Thank you so much! pixielatedd 2 — 1mo
0
No problem MattVSNNL 378 — 1mo
Ad

Answer this question