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

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

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

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.

1 comment

0

Thank you

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