Problem with a script changing Text using a command

local group = 9168107
local minrank = 20

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(Message)
		if Message == ".hide" then
			if player:GetRankInGroup(group) >= minrank then
				for i,v in pairs(game.Players:GetChildren()) do
					v.Character.Head.NameTag.LowerText.Text = "Guest"
					v.Character.Head.NameTag.LowerText.TextColor3 = Color3.fromRGB(218, 218, 218)
				end
			end
		end
	end)
end)

So about my script. When I type “.hide” in chat, it changes their overhead UI nametag rank to “Guest”.
It’s a anonymous feature for my staff to go undercover. But the problem is, when I type “.hide” it also changes for every player in the server as their rank as “Guest”. I only want the person’s rank to change who said the command. Not everyone.

1 Like

Don’t use a for loop if you only want to affect one person

local group = 9168107
local minrank = 20

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(Message)
		if Message == ".hide" then
			if player:GetRankInGroup(group) >= minrank then
				
					player.Character.Head.NameTag.LowerText.Text = "Guest"
					player.Character.Head.NameTag.LowerText.TextColor3 = Color3.fromRGB(218, 218, 218)

			end
		end
	end)
end)
2 Likes

Thank you very much. That worked like a charm. :grinning:

1 Like

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