UserOwnsGamePassAsync not query local players

I keep having this problem where I can’t see the chat of other people whenever I type in the chat box due to my Chat Tags script on my Client Side.

Here’s the script:

TCS.OnIncomingMessage = function(message: TextChatMessage)
	local Prop = Instance.new("TextChatMessageProperties")	

	if message.TextSource then
		local plr = game:GetService("Players"):GetPlayerByUserId(message.TextSource.UserId)
		local PlayerCheck = EventService:WaitForChild("PlayerChecking")
		local GamepassCheck = MPS:UserOwnsGamePassAsync(plr.UserId, GamepassID)
		local RankCheck = plr:GetRankInGroup(groupID)
		
		if RankCheck == 255 then
			if plr and GamepassCheck then
				Prop.PrefixText = "[⭐][👑] " .. message.PrefixText
			else
				Prop.PrefixText = "[👑]" .. message.PrefixText
			end
			--// Same Code goes on here until to the very bottom Rank of Groups which is 0
		end
	end
	return Prop
end

this works, but I’m not able to see other people’s chat nor those people can see other people chat as well. Can someone help me where I went wrong with this??

I also tried doing Server to Client checking if a user owns gamepass, but the remoteEvents aren’t sending values even if I did them correctly (I removed those line of scripts now)

2 Likes

any one can help me with this one? still looking for help

1 Like

It’s kind of hard to understand exactly what’s going wrong without knowing a couple things:

  • What is EventService? Are you sure using WaitForChild on it isn’t causing an infinite yield?
  • Is it just this one gamepass that you are having issues with or does it affect chat no matter what?
  • Are you sure the rest of your function isn’t somehow messing up the message properties?

Also, just a nitpick but for checking ranks instead of making an if statement for every possible rank, you could just make a table that you check and call it a day.

local RankTable = {
  [255] = `[👑]`
}

function GetPrefixText(Player: Player)
    local PlayerRank = Player:GetRankInGroup(GroupID)

    return RankTable[PlayerRank] or ``
end

function OnIncomingMessage(Message)
    ...
    Prop.PrefixText = `{GetPrefixText(Player)}{Message.PrefixText}`
    ...
end
  • What is EventService? Are you sure using WaitForChild on it isn’t causing an infinite yield?

The Event Service should be removed from the script, sorry I forgot. I was trying to use InvokeServer to get Information from Server that this User Owns a Gamepass.

  • Is it just this one gamepass that you are having issues with or does it affect chat no matter what?

This is just one Gamepass, and It affects every users’ chats. For example, if I Chat, it would reflect on my end that it works and the Tag shows, however on other client it doesn’t reflect but their only chat shows only to them.

Basically the chat became for theirselves without actually seeing other people’s chats.

  • Are you sure the rest of your function isn’t somehow messing up the message properties?

I do believe that this part:

		if RankCheck == 255 then
			if plr and GamepassCheck then
				Prop.PrefixText = "[⭐][👑] " .. message.PrefixText
			else
				Prop.PrefixText = "[👑]" .. message.PrefixText
			end
		end

is somehow messing it up, because… this part actually works (script below) and it reflects on my chat that I do own the Gamepass as it checks first if I’m in the rank.

			if plr and GamepassCheck then
				Prop.PrefixText = "[⭐][👑] " .. message.PrefixText
			else
				Prop.PrefixText = "[👑]" .. message.PrefixText
			end

Can you somehow help me get this solved?

Both UserOwnsGamePassAsync and GetRankInGroup can fail, so I added pcall in-order to safely call them. I also removed the TextChatMessageProperties instance since from my experience it doesn’t seem to be necessary to use, and tried rearranging the if statments a bit (also tried to keep a similar naming scheme):

local MPS = game:GetService("MarketplaceService")
local PLR = game:GetService("Players")
local TCS = game:GetService("TextChatService")

TCS.OnIncomingMessage = function(message: TextChatMessage)
	if message.TextSource then
		local player = PLR:GetPlayerByUserId(message.TextSource.UserId)

		local success, rank = pcall(player.GetRankInGroup, player, groupID)

		if success then
			local success, gamepassOwned = pcall(MPS.UserOwnsGamePassAsync, MPS, player.UserId, GamepassID)

			if success then
				if rank == 255 then
					if gamepassOwned then
						message.PrefixText = "[⭐][👑] "..message.PrefixText
					else
						message.PrefixText = "[👑] "..message.PrefixText
					end
				end
			end
		end
	end
end

I’ll try and see if this works, thanks for letting me know about this one. I’ll get with you if I see that it didn’t work for me

1 Like

Update:

The code works, however it only reference the “gamepass” part and it only uses that, the rest it doesn’t reflect on other people whether they have are in a rank or they have the gamepass or both.

In my screen, this is how the chat goes:
[VIP][RANK] User1: Sample Msg1
User2: Sample Msg2
User3: Sample Msg3
User2: Sample Msg4

For example, I’m User1 wherein User2 should have the [RANK] tag shown as well, but does not show. The same goes for people who owns Gamepass (VIP Tag).

I followed @JohhnyLegoKing 's code for this.

1 Like

Separating the if statements should work to fix that problem:

local MPS = game:GetService("MarketplaceService")
local PLR = game:GetService("Players")
local TCS = game:GetService("TextChatService")

TCS.OnIncomingMessage = function(message: TextChatMessage)
	if message.TextSource then
		local player = PLR:GetPlayerByUserId(message.TextSource.UserId)

		local success, rank = pcall(player.GetRankInGroup, player, groupID)

		if success then
			local success, gamepassOwned = pcall(MPS.UserOwnsGamePassAsync, MPS, player.UserId, GamepassID)

			if success then
				if gamepassOwned then
					message.PrefixText = "[👑] "..message.PrefixText
				end

				if rank == 255 then
					message.PrefixText = "[⭐]"..message.PrefixText
				end
			end
		end
	end
end

will that be able to show both tags at the same time if they owned the gamepass and the rank tag itself?

1 Like

It will do so, since the prefix text will be updated accordingly :grin:

if you want multiple tags to show you need to concatenate each tag with each other and concatenate that with the actual message

Alright, I’ll give this a try and get back again with you if I see any error.

1 Like

Hi there ya’ll, I haven’t had a error with the script lately but only 1.

The Tags do show, and it works, however it only shows client to the player and I need it though to show to everyone else in the server.

this is my view:
image

and this is how it looks on my friend’s screen:
image

local MPS = game:GetService("MarketplaceService")
local PLR = game:GetService("Players")
local TCS = game:GetService("TextChatService")

TCS.OnIncomingMessage = function(message: TextChatMessage)
	if message.TextSource then
		local player = PLR:GetPlayerByUserId(message.TextSource.UserId)

		local success, rank = pcall(player.GetRankInGroup, player, groupID)

		if success then
			local success, gamepassOwned = pcall(MPS.UserOwnsGamePassAsync, MPS, player.UserId, GamepassID)

			if success and gamepassOwned then
				if rank == 255 then
					message.PrefixText = "[⭐][👑] "..message.PrefixText
				end
            elseif success and not gamepassOwned then
			message.PrefixText = "[👑] "..message.PrefixText
                        end
			end
		end
	end
end

Ignore this reply it isn’t relevant.

local player = PLR:GetPlayerByUserId(message.TextSource.UserId)
		if player then --check if player found
    		local success, rank = pcall(player.GetRankInGroup, player, groupID)
    		if success and rank == 255 then
    		    message.PrefixText = "[👑] "..message.PrefixText
    		end
    		
    		local success2, gamepassOwned = pcall(MPS.UserOwnsGamePassAsync, MPS, player.UserId, GamepassID)
    		if success2 and gamePassOwned then
    		    message.PrefixText = "[⭐] "..message.PrefixText
    		end
		end

I didn’t need 2 separate if and then statements, because I want it to show 2 tags at the same time whenever they have the VIP Pass not just show 1 Tag.

Everyone here keeps separating those two, this is clearly a Group and Gamepass Chat Tag.

Its either if they don’t own the gamepass, it will only show 1 Tag. And if they owned the gamepass and have a rank, it’ll show 2 Tags where the VIP Star Rank will show first before the Group Rank. Unless that’s what you guys been meaning, because I tried your scripts and it didn’t work (unlike @JohhnyLegoKing 's script because I modified it and still works.)

Does it work for all players if you use a server Script in ServerScriptService instead?

I suggested that because I do remember TCS had a way to get messages on the server-side, I’ll check to see what it was (This info was based on an older version of TCS, my bad)

Ignore this reply it isn’t relevant.

I believe TextChatService don’t work on Server Scripts, its only Client Side.

1 Like

I didn’t need to use FireAllClients on my previous game when I used the same script.

A test you could do is to add a prefix for all players:

local MPS = game:GetService("MarketplaceService")
local PLR = game:GetService("Players")
local TCS = game:GetService("TextChatService")

TCS.OnIncomingMessage = function(message: TextChatMessage)
	if message.TextSource then
		message.PrefixText = "TEST"..message.PrefixText
	end
end

If it doesn’t show up, either something with the way your place is configured is causing the problem to happen or you might be experiencing some kind of bug


Testing prefixes in Studio using a local server in a new baseplate is working correctly for me, so it’s either a configuration issue or a bug that’s specific to the Player


@iiNathxnism I’m noticing that the if statements are different than the code I provided, and the way they’re written the crown will only be provided if the player doesn’t own the gamepass since it’s checking not gamepassOwned:

This would be the correct way to do it:

if success and gamepassOwned then
	if rank == 255 then
		message.PrefixText = "[⭐][👑] "..message.PrefixText
	else
		message.PrefixText = "[👑] "..message.PrefixText
	end
end