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

What should I do to make a 1 hour played badge script?

Asked by 4 years ago

I've been trying for hours, but I can't figure it out. Here is the badge awarding script below:

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

    local badgeID = 2124518441  -- Change this to your badge ID

    local function awardBadge()

        local player = Players.LocalPlayer
        local hasBadge = false

        -- Check if the player already has the badge
        local success, message = pcall(function()
            hasBadge = BadgeService:UserHasBadgeAsync(player.UserId, badgeID)
        end)

        -- If there's an error, issue a warning and exit the function
        if not success then
            warn("Error while checking if player has badge: " .. tostring(message))
            return
        end

        if hasBadge == false then
            BadgeService:AwardBadge(player.UserId, badgeID)
        end
    end
0
You could try using tick() when the player joins the game. Figure out the time elapsed by subtracting the tick() for when the player joined the game and when they leave the game. Then save it using datatstore. Sorukan 240 — 4y
0
yeah or you could just use wait(3600) iiConstable_Subwayx 130 — 4y

1 answer

Log in to vote
0
Answered by
RAFA1608 543 Moderation Voter
4 years ago
local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")

local badgeID = 2124518441  -- Change this to your badge ID

local function awardBadge()

    local player = Players.LocalPlayer
    local hasBadge = false

    -- Check if the player already has the badge
    local success, message = pcall(function()
        hasBadge = BadgeService:UserHasBadgeAsync(player.UserId, badgeID)
    end)

    -- If there's an error, issue a warning and exit the function
    if not success then
        warn("Error while checking if player has badge: " .. tostring(message))
        return
    end

    if hasBadge == false then
        BadgeService:AwardBadge(player.UserId, badgeID)
    end
end
wait(3600) --equivalent to 1 hour in seconds
awardBadge()
--i have no experience with badges so im not sure this would work

hope that helped

0
Forgive me if I'm wrong but believe that won't count total time played and only the total time played from one session. Dreadd15 4 — 4y
0
oh... so in that case youll need to use datastores RAFA1608 543 — 4y
0
but im not sure u can use datastores in a local script RAFA1608 543 — 4y
Ad

Answer this question