Levels chattag problem

Does anyone know how to fix this script? When you chat no matter what another players level is it will display their level (You can be level 7 and chat but someone who is level 1 will think your level 1) and the gamepass won’t work. It works in studio but not in-game.

local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")


TextChatService.OnIncomingMessage = function(message: TextChatMessage)
	local properties = Instance.new("TextChatMessageProperties")

	if message.TextSource then
		local player = Players:GetPlayerByUserId(message.TextSource.UserId)

		if game:GetService("GamePassService"):PlayerHasPass(player, 226471097) then
			properties.PrefixText = "<font color='#edb415'>[VIP]</font> ".."<font color='#67cf13'>[Level "..game.Players.LocalPlayer.Levels.Value.."]</font> " .. message.PrefixText
		else
			properties.PrefixText = "<font color='#67cf13'>[Level "..game.Players.LocalPlayer.Levels.Value.."]</font> " .. message.PrefixText
		end
	end

	return properties
end

because youre getting the level of the localplayer, not the player that sent the message

local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")


TextChatService.OnIncomingMessage = function(message: TextChatMessage)
	local properties = Instance.new("TextChatMessageProperties")

	if message.TextSource then
		local player = Players:GetPlayerByUserId(message.TextSource.UserId)

		if game:GetService("GamePassService"):PlayerHasPass(player, 226471097) then
			properties.PrefixText = "<font color='#edb415'>[VIP]</font> ".."<font color='#67cf13'>[Level "..player.Levels.Value.."]</font> " .. message.PrefixText
		else
			properties.PrefixText = "<font color='#67cf13'>[Level "..player.Levels.Value.."]</font> " .. message.PrefixText
		end
	end

	return properties
end
1 Like

Along with @CZXPEK’s addition, you should also be using MarketplaceService, because GamePassService was deprecated a long time ago.

Code:

--//Services
local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
local TextChatService = game:GetService("TextChatService")

--//Functions
TextChatService.OnIncomingMessage = function(message: TextChatMessage)
	local properties = Instance.new("TextChatMessageProperties")

	if message.TextSource then
		local player = Players:GetPlayerByUserId(message.TextSource.UserId)
		local Levels = player.Levels.Value

		if MarketplaceService:UserOwnsGamePassAsync(player.UserId, 226471097) then
			properties.PrefixText = "<font color='#edb415'>[VIP]</font><font color='#67cf13'>[Level ".. Levels .."]</font>".. message.PrefixText
		else
			properties.PrefixText = "<font color='#67cf13'>[Level ".. Levels .."]</font>".. message.PrefixText
		end
	end

	return properties
end
1 Like

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