Custom Chat Command Issue

So basically I made a system that changes a nametag (billboard GUI) using a custom chat command. The problem is although the command does work, whenever anybody types in the command it affects all players who have the nametag, not just the player who used the command.

Here’s the script:

command = "!sshow"
command2 = "!shide"

local sshow = false

function onChatted(msg, recipient, speaker)
	local source = string.lower(speaker.Name)
	msg = string.lower(msg)
	if (msg == command) and sshow == false then
		sshow = true
		print("TagShown")
	end
	if (msg == command2) and sshow == true then
		sshow = false
		print("TagHidden")
	end
end



function onPlayerEntered(newPlayer)
	newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end) 
end

game.Players.ChildAdded:connect(onPlayerEntered)







local nametag = game.Workspace.DemTags.Testtag.CreatorTags

--Functions
game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		--Varibles
		local head = char.Head
		local newtext = nametag:Clone()
		local uppertext = newtext.PlayerName
		local lowertext = newtext.TeamText
		local image = newtext.Icons.Developer
		local image2 = image.Mobile
		local humanoid = char.Humanoid
		local TERMINATE = game.ServerScriptService.TERMINATE
		
		humanoid.DisplayDistanceType = "None"
		

		
		--Main Text
		newtext.Parent = head
		newtext.Adornee = head
		uppertext.Text = player.Name 
		uppertext.TextColor3 = player.Team.TeamColor.Color
		lowertext.Text = player.Team.Name
		image.Visible = false
		
		

		
		while true do
			wait(0.1)
			if sshow == true and player:GetRankInGroup(8747496) == 254 then 
				image.Visible = true
				image.Image = "rbxassetid://7453101593"
				image2.Image = "rbxassetid://7453101593"
				lowertext.Text = "Chief Executive Officer"
				lowertext.TextColor3 = Color3.fromRGB(57, 57, 57)
			end
			if sshow == true and player:GetRankInGroup(8747496) == 255 then 
				image.Visible = true
				image.Image = "rbxassetid://7558524715"
				image2.Image = "rbxassetid://7558524715"
				lowertext.Text = "Chief Development Officer"
				lowertext.TextColor3 = Color3.fromRGB(57, 57, 57)
			end
			if sshow == true and player:GetRankInGroup(8747496) == 250 then 
				image.Visible = true
				image.Image = "rbxassetid://7737592048"
				image2.Image = "rbxassetid://7737592048"
				lowertext.Text = "Chief Operating Officer"
				lowertext.TextColor3 = Color3.fromRGB(57, 57, 57)
			end
			if sshow == false and player:GetRankInGroup(8747496) > 9 then
				image.Visible = false
				lowertext.TextColor3 = Color3.fromRGB(255,255,255)
				lowertext.Text = player.Team.Name
				lowertext.Visible = true
			end	
		end
	end)
end)
2 Likes

Hello! I might be able to help you, but all I know is there needs to be game.Players.LocalPlayer somewhere. hope I helped!
command = “!sshow”
command2 = “!shide”

local sshow = false

function onChatted(msg, recipient, speaker)
local source = string.lower(speaker.Name)
msg = string.lower(msg)
if (msg == command) and sshow == false then
sshow = true
print(“TagShown”)
end
if (msg == command2) and sshow == true then
sshow = false
print(“TagHidden”)
end
end

function onPlayerEntered(newPlayer)
newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end)
end

game.Players.LocalPlayer.ChildAdded:connect(onPlayerEntered)

local nametag = game.Workspace.DemTags.Testtag.CreatorTags

–Functions
game.Players.LocalPlayer.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
–Varibles
local head = char.Head
local newtext = nametag:Clone()
local uppertext = newtext.PlayerName
local lowertext = newtext.TeamText
local image = newtext.Icons.Developer
local image2 = image.Mobile
local humanoid = char.Humanoid
local TERMINATE = game.ServerScriptService.TERMINATE

	humanoid.DisplayDistanceType = "None"
	

	
	--Main Text
	newtext.Parent = head
	newtext.Adornee = head
	uppertext.Text = player.Name 
	uppertext.TextColor3 = player.Team.TeamColor.Color
	lowertext.Text = player.Team.Name
	image.Visible = false
	
	

	
	while true do
		wait(0.1)
		if sshow == true and player:GetRankInGroup(8747496) == 254 then 
			image.Visible = true
			image.Image = "rbxassetid://7453101593"
			image2.Image = "rbxassetid://7453101593"
			lowertext.Text = "Chief Executive Officer"
			lowertext.TextColor3 = Color3.fromRGB(57, 57, 57)
		end

		if sshow == true and player:GetRankInGroup(8747496) == 255 then 
			image.Visible = true
			image.Image = "rbxassetid://7558524715"
			image2.Image = "rbxassetid://7558524715"
			lowertext.Text = "Chief Development Officer"
			lowertext.TextColor3 = Color3.fromRGB(57, 57, 57)
		end
		if sshow == true and player:GetRankInGroup(8747496) == 250 then 
			image.Visible = true
			image.Image = "rbxassetid://7737592048"
			image2.Image = "rbxassetid://7737592048"
			lowertext.Text = "Chief Operating Officer"
			lowertext.TextColor3 = Color3.fromRGB(57, 57, 57)
		end
		if sshow == false and player:GetRankInGroup(8747496) > 9 then
			image.Visible = false
			lowertext.TextColor3 = Color3.fromRGB(255,255,255)
			lowertext.Text = player.Team.Name
			lowertext.Visible = true
		end	
	end
end)

end)

1 Like

Yes, however the problem is this needs to be a serverside script.

try this

local nametag = game.Workspace.DemTags.Testtag.CreatorTags

--Functions
command = "!sshow"
command2 = "!shide"

game.Players.PlayerAdded:Connect(function(player)
	local tag = nil
	local gr = player:GetRankInGroup(8747496)

	player.Chatted:connect(function(msg)
		local sshow = false
		msg=msg:lower()
		if (msg == command) and sshow == false then
			sshow = true
			print("TagShown")
		end
		if (msg == command2) and sshow == true then
			sshow = false
			print("TagHidden")
		end
		
		if tag and tag:IsDescendantOf(workspace) then
			local uppertext = tag.PlayerName
			local lowertext = tag.TeamText
			local image = tag.Icons.Developer
			local image2 = image.Mobile
			if sshow and gr == 254 then 
				image.Visible = true
				image.Image = "rbxassetid://7453101593"
				image2.Image = "rbxassetid://7453101593"
				lowertext.Text = "Chief Executive Officer"
				lowertext.TextColor3 = Color3.fromRGB(57, 57, 57)
			end
			if sshow and gr == 255 then 
				image.Visible = true
				image.Image = "rbxassetid://7558524715"
				image2.Image = "rbxassetid://7558524715"
				lowertext.Text = "Chief Development Officer"
				lowertext.TextColor3 = Color3.fromRGB(57, 57, 57)
			end
			if sshow and gr == 250 then 
				image.Visible = true
				image.Image = "rbxassetid://7737592048"
				image2.Image = "rbxassetid://7737592048"
				lowertext.Text = "Chief Operating Officer"
				lowertext.TextColor3 = Color3.fromRGB(57, 57, 57)
			end
			if not sshow and gr > 9 then
				image.Visible = false
				lowertext.TextColor3 = Color3.fromRGB(255,255,255)
				lowertext.Text = player.Team.Name
				lowertext.Visible = true
			end	
		end
	end)
	player.CharacterAdded:Connect(function(char)
		--Varibles
		local head = char.Head
		local newtext = nametag:Clone()
		local uppertext = newtext.PlayerName
		local lowertext = newtext.TeamText
		local image = newtext.Icons.Developer
		local image2 = image.Mobile
		local humanoid = char.Humanoid
		local TERMINATE = game.ServerScriptService.TERMINATE

		humanoid.DisplayDistanceType = "None"

		--Main Text
		newtext.Parent = head
		newtext.Adornee = head
		uppertext.Text = player.Name 
		uppertext.TextColor3 = player.Team.TeamColor.Color
		lowertext.Text = player.Team.Name
		image.Visible = false
		
		tag = newtext
	end)
end)

Instead of using the variable sshow, you could instantly hide / show the player’s nametag.

function onChatted(msg, recipient, speaker)
	local source = string.lower(speaker.Name)
	msg = string.lower(msg)
	if (msg == command)  then
		if speaker.Character.NameTag then
                --show nametag
                end
		print("TagShown")
elseif (msg == command2)
if speaker.Character.NameTag then
                --hide nametag
                end
		print("TagHidden")
	end
end

This is because it does not hide the whole tag, only a part of the tag. it hides an image in the tag along with changing some text colors.

On line 25 your function seems to be in game, and its pretty simple game.Players.LocalPlayer.ChildAdded:connect(onPlayerEntered)That might work depending on your game.

So you want to only show specific items of the GUI depending on the group level / rank?

I’ve discovered a bug with your system, whenever the play chats anything besides one of the custom commands, the custom tag goes back to normal.