Problem with giving nametag to player

i have problem i wanna check if player owns gamepass and if he owns give player nametag(prefix) in chat, code dont throw errors but it didnt work as expected

local MPS = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local gpId = 1013492658
local chat = game:GetService("TextChatService")
--local tags = {[0] = {TagText = "TUTORIAL", TagColor = Color3.fromRGB(255, 0, 0)},}
local MarketplaceService = game:GetService("MarketplaceService")
local function checkGamePass(player)
	local success, result = pcall(MarketplaceService.UserOwnsGamePassAsync, MarketplaceService, player.UserId, gpId)

	if success then
		if result then
			print("owns Game Pass")
			chat.OnIncomingMessage = function(message: TextChatMessage)
				local properties = Instance.new("TextChatMessageProperties")
				if message.TextSource then
					local player = Players:GetPlayerByUserId(message.TextSource.UserId)
					properties.PrefixText = "<font color='#9a3e3e'>[Supporter]</font> " .. message.PrefixText
				end
				return properties
			end
		end
			
		
		
		else
			print("does not own Game Pass")

		end
	
    end

for _, player in ipairs(Players:GetPlayers()) do
	checkGamePass(player)
end

Players.PlayerAdded:Connect(checkGamePass)

How does it look in-game and can you show me video or screenshot?

its not displayed at all : for more detailed description i can say text is white above player head created buble with text but in chat only player nickname and message(no errors in output and even print statement)

I think the reason of nametag doesn’t display is it only considers the case of successful possession of the game pass and does not consider the case of failure. How about adding code to retry in case of failure? I tested the code you provided with delete game pass check code, and it runs successfully.

you tested my code and it work for you right?

Yeah, but I tested with not check game pass. So I think it is problem with checking game pass.

And also, if you can’t solve the problem although if you did what I said, please check the script class is LocalScript and its parent is StarterPlayerScripts. it may occur error when its parent is StarterCharacterScripts or else.

1 Like

BRO THANK YOU, i moved to StarterPlayerScripts and it worked

I’m glad it ran well. Have a good day.

1 Like

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