--Services

local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local NameTag = ReplicatedStorage.NameGUI
local ServerStorage = game:GetService("ServerStorage")
local Configurations = require(ServerStorage.Configurations)
local GamepassID = Configurations.GamePassIds.VIP


local function onPlayerAdded(player: Player)

	player.CharacterAppearanceLoaded:Connect(function(character)
		local Head = character.Head or character:WaitForChild("Head")
		local success, result = pcall(function()
			return MarketplaceService:UserOwnsGamePassAsync(player.UserId, GamepassID)
		end)
		if success then
			if result then
		local nameClone = NameTag:Clone()
		
		nameClone.name.Text = "VIP"
		nameClone.Adornee = character.Head
		nameClone.Parent = character.Head
		nameClone.name.Font = Enum.Font.GothamSemibold
		nameClone.name.TextColor3 = Color3.new(1, 1, 0)
		nameClone.name.TextSize = 16

		local humanoid: Humanoid = character:WaitForChild("Humanoid")

		humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
			end
		end
		local s, r = pcall(function()
			return player.MembershipType == Enum.MembershipType.Premium
		end)
		if s then
			if r then
				local nameClone = NameTag:Clone()

				nameClone.name.Text = "Premium"
				nameClone.Adornee = character.Head
				nameClone.Parent = character.Head
				nameClone.name.Font = Enum.Font.GothamSemibold
				nameClone.name.TextColor3 = Color3.new(1, 1, 1)
				nameClone.name.TextSize = 16

				local humanoid: Humanoid = character:WaitForChild("Humanoid")

				humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
			end
		end
	end)
end

Players.PlayerAdded:Connect(onPlayerAdded)
