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

Need help with badge service not awarding second badge?

Asked by
djwchon 10
3 years ago

So I have this script that awards players after staying in-game for 5 seconds. The script is supposed to award players another badge if they already have the previous badge, but I can't get it to work, any help is appreciated.

local badgeservice = game:GetService('BadgeService')
local id = 2124744629
local id2 = 2124814452

function OnPlayerEntered(plr)
    wait(5)
    if not badgeservice:UserHasBadgeAsync(plr.UserId, id) then
        badgeservice:AwardBadge(plr.UserId, id)
        if badgeservice:UserHasBadgeAsync(plr.IserId, id) then
            badgeservice:AwardBadge(plr.UserId, id2)
        end
    end
    wait(2)
    plr:Kick("Congrats, you made it!")
end

game.Players.PlayerAdded:Connect(OnPlayerEntered)
0
Hey i found this in your code try changing it to plr.UserId line 09, source MyoldhamiYeari 0 — 3y
0
Thanks for spotting that but it still doesn't work :( djwchon 10 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago
local badgeservice = game:GetService('BadgeService')
local id = 2124744629
local id2 = 2124814452

function OnPlayerEntered(plr)
    wait(5)
    if not badgeservice:UserHasBadgeAsync(plr.UserId, id) then
        badgeservice:AwardBadge(plr.UserId, id)
        if badgeservice:UserHasBadgeAsync(plr.IserId, id) then
            badgeservice:AwardBadge(plr.UserId, id2)
        end
    end
    wait(2)
    plr:Kick("Congrats, you made it!")
end

game.Players.PlayerAdded:Connect(OnPlayerEntered)

It doesn't work because you might have the badge already, as you see on line 7. If you have the badge already, it will not continue. To fix this, move the second if statement out of the scope.

local badgeservice = game:GetService('BadgeService')
local id = 2124744629
local id2 = 2124814452

function OnPlayerEntered(plr)
    wait(5)
    if not badgeservice:UserHasBadgeAsync(plr.UserId, id) then
        badgeservice:AwardBadge(plr.UserId, id)
    end

    if badgeservice:UserHasBadgeAsync(plr.IserId, id) then
        badgeservice:AwardBadge(plr.UserId, id2)
    end
    wait(2)
    plr:Kick("Congrats, you made it!")
end

game.Players.PlayerAdded:Connect(OnPlayerEntered)
0
Thanks! djwchon 10 — 3y
Ad

Answer this question