Help with chat tags with level system

Hello, I’m working on a game that has a leveling system. I want to make chat tags so other people can see each others level in chat. Right now it gets what the level is and puts that in chat. However when the player levels up the chat stays the same. How can I make this so it checks to see if the level has gone up. I tried a while true do statement but for some reason that did not work.




game.Players.PlayerAdded:Connect(function(player)
wait(1)
        local tags = {
            {
            TagText = "Level ".. player.Stats.Level.Value, 
                TagColor = Color3.fromRGB(255, 255, 0) 
            }
        }
        local ChatService = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner").ChatService)
        local speaker = nil
        while speaker == nil do
            speaker = ChatService:GetSpeaker(player.Name)
            if speaker ~= nil then break end
            wait(0.01)
        end
        speaker:SetExtraData("Tags",tags)
        speaker:SetExtraData("ChatColor",Color3.fromRGB(255, 255, 0)) 
    
end)

I can’t test it at the moment but you’d need to add a loop or changed function to get the new level and update your tag. Something similar to this…

player.leaderstats.Level.Changed:Connect(function(newValue)
    local TagText = TagText(newValue)
    TagText = "Level ".. player.Stats.Level.Value, 
    TagColor = Color3.fromRGB(255, 255, 0)
end)

I tried an while true do loop and had it like this

game.Players.PlayerAdded:Connect(function(player)
wait(1)
local level

while true do 
wait(1)
level = player.Stats.Level.Value
end
local tags = {
            {
            TagText = "Level ".. level, 
                TagColor = Color3.fromRGB(255, 255, 0) 
            }
        }
        local ChatService = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner").ChatService)
        local speaker = nil
        while speaker == nil do
            speaker = ChatService:GetSpeaker(player.Name)
            if speaker ~= nil then break end
            wait(0.01)
        end
        speaker:SetExtraData("Tags",tags)
        speaker:SetExtraData("ChatColor",Color3.fromRGB(255, 255, 0)) 
    
end)

But then nothing was printing out in chat

You won’t need a loop on your “level = player.leaderstats.Level.Value” as that will always update, you’d want it inside where your tags are assigned so as a new level is gained, your tag will change. You could do something like the following although it’s not the most efficient.

while wait(2) do
    local level = player.leaderstats.Level.Value
    TagText = "Level ".. level
    TagColor = Color3.fromRGB(255, 255, 0)
end

player.leaderstats.Level.Changed:Connect(function(newValue)
    local level = level(newValue)
    TagText = "Level ".. level
    TagColor = Color3.fromRGB(255, 255, 0)
end)

I’m kinda confused here, so do I want that inside this?

	local tags = {
		{
			TagText = "Level ".. level, 
			TagColor = Color3.fromRGB(255, 255, 0) 
		}
	}
1 Like

This is not an ideal way but to give you an example of adding a loop to constantly update the value of “Level”.

game.Players.PlayerAdded:Connect(function(player)
	while wait(1) do
	local level = player.leaderstats.Level
	local tags = {
		{
			TagText = "Level ".. (level.Value), 
			TagColor = Color3.fromRGB(255, 255, 0) 
		}
	}
	local ChatService = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner").ChatService)
	local speaker = nil
	while speaker == nil do
		speaker = ChatService:GetSpeaker(player.Name)
		if speaker ~= nil then break end
		wait(0.01)
	end
		speaker:SetExtraData("Tags",tags)
		speaker:SetExtraData("ChatColor",Color3.fromRGB(255, 255, 0)) 
		
	end
end)

1 Like