Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

how to give a badge if a user is connected?

Asked by 1 year ago

i want do like a badge that can you get if i am connected to that server how can i do that?

and other ask is how can i make to check if a user have a badge and in a like gui show it diferent or whit a withe mark?

2 answers

Log in to vote
1
Answered by 1 year ago
Edited 1 year ago

In my opinion, this is the easiest way to do it, at least semi-efficiently – this does not mean this script is perfect.

First, we have to make a function to check if the Owner is in the Server already so when a player joins we can and if the Owner is, we can award them the badge. For this, we iterate over each player in the server and check if one of their names equals to the Owner's name.

local function OwnerInServer()
    for _,plr in pairs(Players:GetPlayers()) do
        if plr.Name == OwnerUsername then
            return true
        end
    end
    return false
end

Of course, as mentioned above, we have to check for each player joining if the Owner is in the server. Though, we also have to consider the possibility of the Owner being the one to join the Server instead. So basically if the player joining is the Owner, we give each player in the server the badge, and if not, we give each player joining after that the badge.

Players.PlayerAdded:Connect(function(player)
    if player.Name == OwnerUsername then
        for _,plr in pairs(Players:GetPlayers()) do
            BadgeService:AwardBadge(plr.UserId, BadgeId)
        end
    elseif OwnerInServer() then
        BadgeService:AwardBadge(player.UserId, BadgeId)
    end
end)

Finishing this off with a few variables and the right services, should leave you with a script that looks something like this.

local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
local BadgeId = 000000000
local OwnerUsername = "solo_degenme" -- Guessing that you're the Owner in this case.

-- Function to check if a player with OwnerUsername as username is in the server
-- Could use UserId, but didn't here for demonstration purposes
local function OwnerInServer()
    for _,plr in pairs(Players:GetPlayers()) do
        if plr.Name == OwnerUsername then
            return true
        end
    end
    return false
end

Players.PlayerAdded:Connect(function(player)
    -- If the player that joined is the Owner, award the badge to every player already in the server
    if player.Name == OwnerUsername then
        for _,plr in pairs(Players:GetPlayers()) do
            BadgeService:AwardBadge(plr.UserId, BadgeId)
        end
    -- If the player that joined is not the Owner, check if the Owner is in the server and if so – award the badge
    elseif OwnerInServer() then
        BadgeService:AwardBadge(player.UserId, BadgeId)
    end
end)

If there are any issues regarding the script, please write a comment, as I wrote this without prior testing.

Note that I wouldn't consider this spoon-feeding, as he could've just as well googled for a tutorial if he wanted to copy it.

1
very detailed Puppynniko 1059 — 1y
Ad
Log in to vote
0
Answered by 1 year ago

Hi, I found a tutorial for you on the meet the owner badge here: Youtube And also for the other part your going to want to check if a player owns the badge

Then if they do. Using an if statement you are going to want to enable a image label on top of the badge image gui. In photoshop you can add a checkmark onto the badge thumbnail and upload it as a decal. Hope this makes sense to you and helps!!

Answer this question