Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Need help with badge service not awarding second badge?

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)

2 comments

0

Hey i found this in your code try changing it to plr.UserId line 09, source

0

Thanks for spotting that but it still doesn't work :(

1 answer

✓ Accepted answer
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)

1 comment

0

Thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.