Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I put an if statement with a table?

So I'm trying to figure out how to make a certain tag appear if a player ID is equal to one of the id's in the table. the tag part itself works fine if i put my id where "admins" is. I just can't figure out how to make it so it will have the tag appear for any of the players in the table.

local nametag = game.ServerStorage.nameTag
local cloned = nametag:Clone()
local character = script.Parent
local player = game.Players:FindFirstChild(character.Name)

local admins = {
    43764376; --baxzzi
    123268417; --canadian_kidgamer
    86489853; --JonathanParkourPro
}

local debug = game.ServerScriptService.debugMode.Value

cloned.Parent = character.Head
cloned.Adornee = character.Head
cloned.type1.Visible = true

cloned.type1.line1.Text = "Player ".."(".. character.name ..")"
cloned.type1.imageFrame.Visible = true

if player.UserId == admins then -- Admin Tag
    cloned.type1.imageFrame.Size = UDim2.new(0.35,0,0.3,0)
    cloned.type1.imageFrame.Position = UDim2.new(0.32,0,0.3,0)
    cloned.type1.imageFrame.ImageColor3 = Color3.fromRGB(255, 82, 85)
    cloned.type1.imageFrame.rank.Text = "ADMIN"
end

1 answer

✓ Accepted answer

You can do this with loops to iterate through the table and match id's. You can also use a dictionary style of table to look up a key, in this case, the users id.

Edit due to ideas in comments

  • @DinozCreates and @RubenKan
local players = game:GetService('Players')
local me = players:GetPlayerFromCharacter(script.Parent)
local character = me.Character
local head = character:WaitForChild("Head")

local nametag = game.ServerStorage:WaitForChild("nameTag")
local cloned = nametag:Clone()
local type1 = cloned:WaitForChild("type1")
local line1 = type1:WaitForChild("line1")
local imageFrame = type1:WaitForChild("imageFrame")
local rank = imageFrame:WaitForChild("rank")

local debug = game.ServerScriptService.debugMode.Value

local admins = {
 	[43764376] = true;
	[123268417] = true;
	[86489853] = true;
}

cloned.Parent = head
cloned.Adornee = head
cloned.type1.Visible = true
line1.Text = "Player ".."(".. me.name ..")"
imageFrame.Visible = true

if admins[me.userId] then 
	imageFrame.Size = UDim2.new(0.35,0,0.3,0)
	imageFrame.Position = UDim2.new(0.32,0,0.3,0)
	imageFrame.ImageColor3 = Color3.fromRGB(255, 82, 85)
	rank.Text = "ADMIN"
else
	print('not admin')
end

4 comments

0

Would just using the ID's be better in case a player name changes?

0

i'd use {[001] = true; [002] = true} etc. with if Admins[Player.UserId] then

0

I guess he can just comment the names then ~

0

Thanks so much, works just like I needed it to. :)

This discussion is preserved as it was. New answers, comments, and votes are closed.