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

how would i give a badge when someone reaches an amount of exp?

Asked by 6 years ago

this is the script i have at the moment

for i, v in pairs(game.Players:GetPlayers()) do
        if v.leaderstats.EXP.Value >= 50000 then 
            if badgeService:UserHasBadge(v.userId, fiftybadgeID[i]) and v.fiftythousandexpbadge.Value == 0 then
                print('has 50k badsge')
                v.fiftythousandexpbadge.Value = v.fiftythousandexpbadge.Value + 1
            else
                badgeService:AwardBadge(v.userId, 1324632095)
            end
        end
    end
end

1 answer

Log in to vote
0
Answered by
Griffi0n 315 Moderation Voter
6 years ago

I'm a little confused as to why you are using a for loop iterate through the players rather than using a localscript. but here's the fix.

while true do
    for i, v in pairs(game.Players:GetPlayers()) do
            if v.leaderstats.EXP.Value >= 50000 then 
                if badgeService:UserHasBadge(v.userId, fiftybadgeID[i]) and v.fiftythousandexpbadge.Value == 0 then
                    print('has 50k badsge')
                    v.fiftythousandexpbadge.Value = v.fiftythousandexpbadge.Value + 1
                else
                    badgeService:AwardBadge(v.userId, 1324632095)
                end
            end
        end
    end
    wait()
end

For loops in pairs iterate through all the values of an array and then stop so it would only iterate once. I am assuming that you want to iterate forever.

0
Thank you OrdinaryBearpanda4 0 — 6y
Ad

Answer this question