Hi! I’m very new to scripting in Roblox and I got stuck on this one issue I’ve been trying to resolve.
I made a Server-Side Script inside the ServerScriptService property, where once the player is added it will check to see if it had reached to a certain point of leaderstats value (in this case I’m using Level as my leaderstats value). Basically what I want is when the player reaches level 5, 10, 25, 50, 75, 100, and 1000, they will be rewarded with a unique badge as an accomplishment.
The PROBLEM is that when they level up to 5 they get a badge, but after they level up to 10, 25, 50, 75, 100, or even 1000, the script won’t award the player those badges to them for some reason.
Now, I tried to combat this issue by adding a then return end statement (meaning if they already have this badge then it will not give them this badge again) before they get the badge award, but it still didn’t do anything.
I also tried troubleshooting by using print, but all the output said was “got lvl 5 badge” even though I was already above Level 5 and even when I was Level 10.
MY GOAL: I want the player and other players be awarded with all the other level up badges.
This is my Code from my Sever-Side Script inside of ServerScriptService:
local BadgeService = game:getService("BadgeService")
game.Players.PlayerAdded:Connect(function(player)
local ls = player:WaitForChild("leaderstats")
local lvl = ls.Level
lvl:GetPropertyChangedSignal("Value"):Connect(function()
if lvl.Value >= 5 then
if BadgeService:UserHasBadgeAsync(player.UserId, 2149272660) then return end
BadgeService:AwardBadge(player.UserId, 2149272660)
print("got lvl 5 badge")
elseif lvl.Value >= 10 then
if BadgeService:UserHasBadgeAsync(player.UserId, 2149272708) then return end
BadgeService:AwardBadge(player.UserId, 2149272708)
print("got lvl 10 badge")
elseif lvl.Value >= 25 then
if BadgeService:UserHasBadgeAsync(player.UserId, 2149272758) then return end
BadgeService:AwardBadge(player.UserId, 2149272758)
print("got lvl 25 badge")
elseif lvl.Value >= 50 then
if BadgeService:UserHasBadgeAsync(player.UserId, 2149272786) then return end
BadgeService:AwardBadge(player.UserId, 2149272786)
print("got lvl 50 badge")
elseif lvl.Value >= 75 then
if BadgeService:UserHasBadgeAsync(player.UserId, 2149272825) then return end
BadgeService:AwardBadge(player.UserId, 2149272825)
print("got lvl 75 badge")
elseif lvl.Value >= 100 then
if BadgeService:UserHasBadgeAsync(player.UserId, 2149272859) then return end
BadgeService:AwardBadge(player.UserId, 2149272859)
print("got lvl 100 badge")
elseif lvl.Value >= 1000 then
if BadgeService:UserHasBadgeAsync(player.UserId, 2149272877) then return end
BadgeService:AwardBadge(player.UserId, 2149272877)
print("got lvl 1000 badge")
end
end)
end)