How can I have my game run a command if a player joins with a badge?

I’m trying to figure out how to get a script to run a command that reveals a part/model when the user joins with a certain badge, sort of like Get A Snack At 3 AM’s trophy ending system.

I’m not going to write the code for you but it would be pretty simple and be along the lines of …

On player join ... (Players.PlayerAdded) -> If player has badge... (BadgeService:UserHasBadgeAsync) -> Your code here if player has badge.

Here’s an example script which you can work from (needs to be a server script).

local players = game:GetService("Players")
local badges = game:GetService("BadgeService")

local badgeId = 0 --Change to ID of badge.

players.PlayerAdded:Connect(function(player)
	local success, result = pcall(function()
		return badges:UserHasBadgeAsync(player.UserId, badgeId)
	end)
	
	if success then
		if result then
			print(result)
			--Do code here if the player owns the badge.
		else
			--Do code here if the player doesn't own the badge.
		end
	else
		warn(result)
	end
end)