How to award a badge to Premium user?

Hey devs!

So I’m trying to add a badge to my experience that will be awarded to users who has Roblox Premium subscription on when they join.

I tried scripting it multiple times, but i failed.

Can anyone please help me? It would really help me out.

Thanks in advance,
jeziskrista

You can use a player joined event and check to see whether their current membership is premium with this code:
Place this script into ServerScriptService

--//SERVICES
local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")

--//VARIABLES
local BadgeId = 12345678 -- replace this id with your badge id

--//RUNTIME
Players.PlayerAdded:Connect(function(player)

	if player.MembershipType == Enum.MembershipType.Premium then
		local success, result = pcall(function()
         -- handles giving the badge to the player
			return BadgeService:AwardBadge(player.UserId, BadgeId)
		end)
         -- debugging if  necessary, can be deleted.
		if success then
			if result then
				print(player.Name .. " has been awarded the badge.")
			else
				print(player.Name .. " already owns the badge.")
			end
		else
			warn("Failed to award badge to " .. player.Name .. ": " .. result)
		end
	end

end)
4 Likes

Thank you so much! This helped me a lot!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.