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

How do I make a badge that get given when touching a brick?

Asked by 4 years ago

So I tried to see anyways too do it, and they are all outdated so I need some help. See I'll do this code but what would I do to make it for a one badge?

local BadgeService = game:GetService("BadgeService")

    local function awardBadge(player, badgeId)
        -- check badge can be awarded
        if BadgeService:IsLegal(badgeId) and not BadgeService:IsDisabled(badgeId) then
            -- award badge
            BadgeService:AwardBadge(player.UserId, badgeId)
        end
    end

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

They aren't outdated, you didn't make a touch event for the badge also make sure that your Badge Id is correct.

local badgeId = -- Your badge Id

script.Parent.Touched:Connect(function(hit)

if hit.Parent:FindFirstChild("Humanoid")

local BadgeService = game:GetService("BadgeService")

    local function awardBadge(player, badgeId)
        -- check badge can be awarded
        if BadgeService:IsLegal(badgeId) and not BadgeService:IsDisabled(badgeId) then
            -- award badge
            BadgeService:AwardBadge(player.UserId, badgeId)
              end
        end
    end
end)
Ad
Log in to vote
0
Answered by 4 years ago

use the humanoid.touched or the part touched and then add a script to give you a badge here is a script to give a badge

local BadgeService = game:GetService("BadgeService")

    local function awardBadge(player, badgeId)
        -- check badge can be awarded
        if BadgeService:IsLegal(badgeId) and not BadgeService:IsDisabled(badgeId) then
            -- award badge
            BadgeService:AwardBadge(player.UserId, badgeId)
        end
    end

Here is a met the owner badge

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

    -- change these
    local OWNER_ID = 212423 -- can use game.CreatorId for published places
    local BADGE_ID = 1

    local ownerInGame = false

    local function playerAdded(newPlayer)
        if newPlayer.UserId == OWNER_ID then
            -- if new player is the owner, set ownerInGame to true and give everyone the badge
            ownerInGame = true
            for _, player in pairs(Players:GetPlayers()) do
                -- don't award the owner
                if player ~= newPlayer then
                    BadgeService:AwardBadge(player.UserId, BADGE_ID)
                end
            end
        elseif ownerInGame then 
            -- if the owner is in the game, award the badge
            BadgeService:AwardBadge(newPlayer.UserId, BADGE_ID)
        end
    end

    local function playerRemoving(oldPlayer)
        if oldPlayer.UserId == OWNER_ID then
            -- set ownerInGame to false
            ownerInGame = false 
        end
    end

    -- listen for players joining and leaving
    Players.PlayerAdded:Connect(playerAdded)
    Players.PlayerRemoving:Connect(playerRemoving)

    -- fire playerAdded for existing players
    for _, player in pairs(Players:GetPlayers()) do
        playerAdded(player)
    end

Answer this question