Trying to turn off an attribute for specific user IDs

I’m trying to make a VIP chat tag for my game. All VIPs in my game are friends with me. However, so are my admins. I want to give the VIP tag to the VIPs but make sure the admin tag does not get overridden. There are also specific VIPs who do not want the VIP tag, so they are also included.

I’ve been doing chat tags via Attributes. So, I want all the VIPs (who are not excluded or admin) to have the VIP attribute. Admins and excluded users should not have the VIP attribute.

I’ve tried looping through the list of admin user IDs but it just doesn’t work.

Here’s my code.

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

local admins = {1425735583,76819254,1165295122,104952955,3241852445}
local exclude = {989350009,4760223737}

Players.PlayerAdded:Connect(function(player)

	if player:IsFriendsWith(1425735583) then
		
		player:SetAttribute("VIP", true)
		print("attribute given to user"..player.Name)
		
		for index = 1, #admins do
			player:SetAttribute("VIP", false)
			print("attribute removed from user"..player.Name)
		end
		
		for index = 1, #exclude do
			player:SetAttribute("VIP", false)
			print("attribute removed from user"..player.Name)
		end
		
		
	end

end)

I work best with visual aids, so if you work with this code some, please post it. Thanks.

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

local admins = {
	[1425735583] = true,
	[76819254] = true,
	[1165295122] = true,
	[104952955] = true,
	[3241852445] = true
} -- make them both a dictionary instead of a table so we can index the userId

local exclude = {
	[989350009] = true,
	[4760223737] = true
}

Players.PlayerAdded:Connect(function(player)
	if player:IsFriendsWith(1425735583) then
		if exclude[player.UserId] or admins[player.UserId] then return end -- check if they are an admin or excluded BEFORE giving them the VIP tag
		player:SetAttribute("VIP", true)
		print("attribute given to user"..player.Name)
	end
end)
-- all of the other code is good 👍 nice job

Thanks much! Didn’t even think of using dictionaries.

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