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)