So while testing a game of mine, I’ve been getting the same badge which I’ve already gotten a long time ago. I’ve rejoined and I get the badge again. I tested this with another game and it gives me the same result. This is quite weird, never happened before.
The script I’m using, although I think it’s something with Roblox’s end.
local badgeservice = game:GetService("BadgeService")
local id = 2124897618
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid")then
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
badgeservice:AwardBadge(plr.UserId,id)
end
end)
In the video provided, it appears that the two badges given were actually different badges. One says “Grassland” and the other says “Welcome”. Maybe I’m missing something. Make sure your script isn’t accidentally duplicated anywhere either. Hope this helps.
It’s not that, I already have those badges. I’ve gotten those badges a month ago but it seems like now I can get the same exact badges more than once after rejoining which is very odd. This is also happening with other games. Getting the same badge more than once after rejoining.
You can test it for yourself, if you have gotten the badge, rejoin the game it’ll give you the badge once again. Don’t if this is on my end or something…
Okay, I think I found a way to check if the user has a badge already, before awarding it.
local badgeservice = game:GetService("BadgeService")
local id = 2124897618
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid")then
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if badgeservice:UserHasBadgeAsync(plr.UserId,id) then return
else
badgeservice:AwardBadge(plr.UserId,id)
end
end
end)
I don’t think you seem to get what I’m saying. Try out this game: Escape Easy Admin Obby - Roblox and rejoin after you get the “welcome” badge, it’ll give you the same badge every time you rejoin. It doesn’t seem to be a error with the code I have, seems like a Roblox Bug, at least that’s what I assume.
It’s actually not happening to me with the welcome badge, so I thought it was just you, but then I realized, that I do get awarded that badge every time I slide down that first slide.
Why wouldn’t the code I provided work?
if badgeservice:UserHasBadgeAsync(plr.UserId,id) then
This returns a true or false value as to whether this specific player has the badge or not, if true, the script should end and not award a badge at all.
Were you able to test that additional line?
BTW I re-wrote it to be a bit cleaner below.
local badgeservice = game:GetService("BadgeService")
local id = 2124897618
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid")then
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if not badgeservice:UserHasBadgeAsync(plr.UserId,id) then
badgeservice:AwardBadge(plr.UserId,id)
end
end
end)
The badges don’t duplicate, it’s just that Roblox doesn’t check if the player owns the badge first before showing the “Badge Awarded” notification in-game, but checks if the player owns it internally for the inventory. You should check if the player doesn’t own the badge with BadgeService:UserHasBadgeAsync before awarding the badge with AwardBadge.
Ohh, wow I thought this was a bug or something. Alright so it does seem to get fixed, although for the welcome one, it gives badges to all players whenever they join, how would I fix this?
local BadgeService = game:GetService("BadgeService")
local badgeId = 2124890464
game.Players.PlayerAdded:Connect(function(player)
local playerUserId = player.UserId
wait(3)
BadgeService:AwardBadge(playerUserId, badgeId)
print("Thanks for playing! :)")
end)
```
Seems like this could be fixed the same way as the other one. Just double check that they don’t already have it before awarding it.
local BadgeService = game:GetService("BadgeService")
local badgeId = 2124890464
game.Players.PlayerAdded:Connect(function(player)
local playerUserId = player.UserId
wait(3)
if not BadgeService:UserHasBadgeAsync(plr.UserId,id) then
BadgeService:AwardBadge(plr.UserId,id)
print("Thanks for playing! :)")
else print("Welcome Back! :)")
end)
Glad I could help!
I might also add that you could trigger the badge once the character is loaded rather than using wait(3). This would prevent users with longer loading time not seeing the badge being awarded to them. I also noticed your variables don’t match such as player and plr. So I fixed those below as well.
local BadgeService = game:GetService("BadgeService")
local badgeId = 2124890464
game.Players.PlayerAdded:Connect(function(plr)
local id = plr.UserId
plr.CharacterAppearanceLoaded:Connect(function() --Using CharacterAppearanceLoaded instead of CharacterAdded ensures that all services are running for this player.
if not BadgeService:UserHasBadgeAsync(plr.UserId,id) then
BadgeService:AwardBadge(plr.UserId,id)
print("Thanks for playing! :)")
else print("Welcome Back! :)")
end
end)
if plr then plr = nil return end --Ensures that this script isn't fired every time the player respawns, just the first time they load.
end)