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

badge awarded based off of leaderboard stats?

Asked by 5 years ago

this wasnt my script and i know how most of it works so I tried to edit it and add more badges but for some reason they wont be given out :(



-- services local plrServ = game:GetService("Players") local badgeService = game:GetService("BadgeService") -- var local badgeId = 2100422700 local badge2Id = 2100404188 local badge3Id = 2100402260 plrServ.PlayerAdded:connect(function(plr) local Stats = Instance.new("Model") Stats.Name = "leaderstats" local Timer = Instance.new("IntValue") Timer.Name = "Time Wasted" Timer.Parent = Stats Stats.Parent = plr -- add the event only for player who do not own the badge if not badgeService:UserHasBadge(plr.UserId, badgeId ) then local con -- needs to be defined first con =Timer.Changed:Connect(function(newVal) if newVal == 60 then badgeService:AwardBadge(plr.UserId, badgeId) con:Disconnect() -- disconnect this event end end) end end) -- add the event only for player who do not own the badge if not badgeService:UserHasBadge(plr.UserId, badge2Id ) then local con -- needs to be defined first con =Timer.Changed:Connect(function(newVal) if newVal == 600 then badgeService:AwardBadge(plr.UserId, badge2Id) con:Disconnect() -- disconnect this event end end) -- add the event only for player who do not own the badge if not badgeService:UserHasBadge(plr.UserId, badge3Id ) then local con -- needs to be defined first con =Timer.Changed:Connect(function(newVal) if newVal == 6000 then badgeService:AwardBadge(plr.UserId, badge3Id) con:Disconnect() -- disconnect this event end end) -- add time for all players -- not this will mean they share the same clock while true do wait(60) for _, plr in pairs(plrServ:GetPlayers()) do -- find stats local leaderStats = plr:FindFirstChild("leaderstats") if leaderStats then local timeVal = leaderStats:FindFirstChild("Time Wasted") if timeVal then timeVal.Value = timeVal.Value + 1 end end end end

1 answer

Log in to vote
1
Answered by 5 years ago

Ah. Ok so this is a simple and hard to notice mistake. Your first badge award is included in the PlayerAdded function but the other two aren't. Replace the entire script with this and tell me if it works.

-- services
local plrServ = game:GetService("Players")
local badgeService = game:GetService("BadgeService")

-- var
local badgeId = 2100422700
local badge2Id = 2100404188
local badge3Id = 2100402260

plrServ.PlayerAdded:connect(function(plr)
    local Stats = Instance.new("Model")
    Stats.Name = "leaderstats"
    local Timer = Instance.new("IntValue")
    Timer.Name = "Time Wasted"
    Timer.Parent = Stats 
    Stats.Parent = plr

    -- add the event only for player who do not own the badge
    if not badgeService:UserHasBadge(plr.UserId, badgeId ) then
        local con -- needs to be defined first
        con =Timer.Changed:Connect(function(newVal)
            if newVal == 60 then
                 badgeService:AwardBadge(plr.UserId, badgeId)
                con:Disconnect() -- disconnect this event
            end
        end)
     end

    -- add the event only for player who do not own the badge
    if not badgeService:UserHasBadge(plr.UserId, badge2Id ) then
        local con -- needs to be defined first
        con =Timer.Changed:Connect(function(newVal)
            if newVal == 600 then
                 badgeService:AwardBadge(plr.UserId, badge2Id)
                con:Disconnect() -- disconnect this event
            end
        end)
    end 

    -- add the event only for player who do not own the badge
    if not badgeService:UserHasBadge(plr.UserId, badge3Id ) then
        local con -- needs to be defined first
        con =Timer.Changed:Connect(function(newVal)
            if newVal == 6000 then
                 badgeService:AwardBadge(plr.UserId, badge3Id)
                con:Disconnect() -- disconnect this event
            end
        end)
   end

end)

-- add time for all players
-- not this will mean they share the same clock
while true do
    wait(60)
    for _, plr in pairs(plrServ:GetPlayers()) do

       -- find stats
        local leaderStats = plr:FindFirstChild("leaderstats")
        if leaderStats then
            local timeVal = leaderStats:FindFirstChild("Time Wasted")
            if timeVal then
                timeVal.Value = timeVal.Value + 1
            end
        end
    end
end
Ad

Answer this question