Why Is it still giving me armor even though I made a if statement?

So Basically I made armor that only certain people can have if their UserID is in the playerID table. The thing is that they get the unique armor and the regular armor. How can I make it so they still don’t get the common armor?

local playerId = {58508301, 29129921, 21011200}
local player = game:GetService("Players")
local ArmorModule = require(script:WaitForChild("ArmorModule"))
local player = game.Players.PlayerAdded:Connect(function(player)
	local Character = player.CharacterAdded:Connect(function(character)
		local ReplicatedStorage = game:GetService("ReplicatedStorage")
		
		for i, playerIds in pairs(playerId) do
			if player.UserId == playerIds then 
				
		
					
			local BerserkMask = game:GetService("ServerStorage").BHead:Clone()
			BerserkMask.Parent = character
			local weld3 = Instance.new("Weld",character)
			weld3.Name = "HeadWeld"
			weld3.Part0 = character.Head
			weld3.Part1 = BerserkMask.PrimaryPart
			weld3.C1 = CFrame.Angles(math.rad(-85.92),math.rad(4.56),math.rad(170.7))
			ArmorModule.SpecialArmor(player, character, player.UserId) -- Sharing the character and player with the module script
				
				
			elseif player.UserId ~= playerIds  then
				
				
				local Clothes = game:GetService("ServerStorage")["3DClothe"]:Clone()
				Clothes.Parent = character
				
				local cape = game:GetService("ServerStorage").CapeMesh:Clone()
				cape.Parent = character
				
				for Index, Clothes in pairs(Clothes:GetChildren()) do

					for index, Newplayer in pairs(character:GetChildren()) do


						if Clothes.Name == Newplayer.Name  then
							Clothes.PrimaryPart.CFrame = Newplayer.CFrame

							local weld = Instance.new("Weld")
							weld.Part0 = Newplayer
							weld.Part1 = Clothes.PrimaryPart
							weld.Parent = Clothes.Parent
							
							local weld2 = Instance.new("Weld",character)
							weld2.Name = "CapeWeld"
							weld2.Part0 = character.PrimaryPart
							weld2.Part1 = cape
							weld2.C1 = CFrame.new(0,2,-0.2)


						end
					end
				end
			end
			
		end
		
	end)
end)
1 Like

Try changing your for statement to this:

for i = 1, #playerId do
  if player.UserId == playerId[i] then

As an alternative, you would use iPairs and not Pairs.
Please refer to this article:

still didn’t work. I don’t know what to do. the two armors are still overlapping

you are looping through the table rather than checking if the table includes the userid, use table.find

local playerId = {58508301, 29129921, 21011200}
local player = game:GetService("Players")
local ArmorModule = require(script:WaitForChild("ArmorModule"))
local player = game.Players.PlayerAdded:Connect(function(player)
	local Character = player.CharacterAdded:Connect(function(character)
		local ReplicatedStorage = game:GetService("ReplicatedStorage")
		
		if table.find(playerId, player.UserId) then
		
					
			local BerserkMask = game:GetService("ServerStorage").BHead:Clone()
			BerserkMask.Parent = character
			local weld3 = Instance.new("Weld",character)
			weld3.Name = "HeadWeld"
			weld3.Part0 = character.Head
			weld3.Part1 = BerserkMask.PrimaryPart
			weld3.C1 = CFrame.Angles(math.rad(-85.92),math.rad(4.56),math.rad(170.7))
			ArmorModule.SpecialArmor(player, character, player.UserId) -- Sharing the character and player with the module script
				
				
		else
				
            local Clothes = game:GetService("ServerStorage")["3DClothe"]:Clone()
            Clothes.Parent = character
            
            local cape = game:GetService("ServerStorage").CapeMesh:Clone()
            cape.Parent = character
            
            for Index, Clothes in pairs(Clothes:GetChildren()) do

                for index, Newplayer in pairs(character:GetChildren()) do


                    if Clothes.Name == Newplayer.Name  then
                        Clothes.PrimaryPart.CFrame = Newplayer.CFrame

                        local weld = Instance.new("Weld")
                        weld.Part0 = Newplayer
                        weld.Part1 = Clothes.PrimaryPart
                        weld.Parent = Clothes.Parent
                        
                        local weld2 = Instance.new("Weld",character)
                        weld2.Name = "CapeWeld"
                        weld2.Part0 = character.PrimaryPart
                        weld2.Part1 = cape
                        weld2.C1 = CFrame.new(0,2,-0.2)
                    end
                end
            end	
		end
	end)
end)

Interesting, I’ve only heard of Table.Find a few times. Learning something new everyday. I’ll test this out in a minute

I have a question. So whats the difference between using table.find and If player.UserID == Playerids? Aren’t we still checking if the player’s ID is in the table? PS. IT WORKED

nah, you loop through every object in the table, and you check if the id == the player’s id
however, this gets checked once for every id in the table, so it will check the id 3 times
table.find just checks if it exists without having to use a pairs loop

Fox Could you help me with one more problem it still has to do with tables, and unique IDS and stuff. So basically if It has the unique ID it’ll give unique Aura, but if they don’t have it it gives them regular aura. But the thing is when someone with the unique aura turns it on the other person gets it too. how to fix?

Regular Is Purple, Unique is Gold

local AuraRemote = script.Parent
local AuraModule = require(game.StarterPlayer.StarterCharacterScripts["Aura!"]:WaitForChild("AuraModule"))

local playerID = {
	58508301,
	15454353, 
	2023345}


AuraRemote.OnServerEvent:Connect(function(player,  On)
	local character = player.Character
	local Humanoid = character.Humanoid
	local HumanoidRootPart = character.HumanoidRootPart
	if  On == true then 
		
		
		
		if table.find(playerID, player.UserId) then
				AuraModule.UniqueAura(player.UserId,  character)	
		end
		
		AuraModule.Aura(player, player.UserId,  character)
		task.wait(1)
		warn("Awakened")
	
	else
		
		
		
		AuraModule.TurnOffAura(player, player.UserId,  character)
		warn("Normal Form")
		
		
	end

	

	
end)
	```

that’s odd, I don’t know why it would be enablling the aura for other players, it might be an issue in your aura module

Heres the aura module:

local replicatedstorage = game:GetService("ReplicatedStorage")
local aura = replicatedstorage.Aura
local Aura1 = aura.Aura1Effect:Clone()
local Aura2 = aura.Embers:Clone()
local EyeRedLeft = aura:WaitForChild("ParticleEmitterRedLeft")
local EyeRedRight = aura:WaitForChild("ParticleEmitterRedRight")
local Shineleft = aura.shineLeft:Clone()
local ShineRight = aura.shineRight:Clone()
local AuraBloom1 = aura.Aura1Bloom:Clone()
local AuraBloom2 = aura.AuraBloom2:Clone()





local playerID = {
	58508301,
	15454353, 
	2023345

}


local Module = { }
--(player, player.UserId,  character)
function Module.Aura(player, UserId,Character)

	

		local Head = Character.Head
		local RightArm = Character["Right Arm"]
		local LeftArm = Character["Left Arm"]
		local LeftLeg = Character["Left Leg"]
		local RightLeg = Character["Right Leg"]
		local Torso = Character.Torso
		local HumanoidRootPart = Character.HumanoidRootPart
		--Attachments
		
		local AttachmentLeft = Instance.new("Attachment")
		AttachmentLeft.Position = Vector3.new(0.204, 0.221, -0.6)
		AttachmentLeft.Name = "AttachmentLeft"
		AttachmentLeft.Parent = Head
		

		local AttachmentRight = Instance.new("Attachment")
		AttachmentRight.Position = Vector3.new(-0.192, 0.216, -0.6)
		AttachmentRight.Name = "AttachmentRight"
		AttachmentRight.Parent = Head
		
		
		local SpecialPartAttachment1 = Instance.new("Attachment")
		--SpecialPartAttachment1.CFrame = HumanoidRootPart.CFrame * CFrame.new(0,-2.32,0)
		SpecialPartAttachment1.Name = "SpecialPartAttachment1"
		
		
		local SpecialPartAttachment2 = Instance.new("Attachment")
		--SpecialPartAttachment2.CFrame = HumanoidRootPart.CFrame * CFrame.new(0,-2.32,0)
		SpecialPartAttachment2.Name = "SpecialPartAttachment1"
		
		
		local SpecialAttachment3 = Instance.new("Attachment")
	SpecialAttachment3.Name = "SpecialAttachment3"
	
	local SpecialAttachment4 = Instance.new("Attachment")
	SpecialAttachment4.Name = "SpecialAttachment4"
	
	
		--SpecialAttachment3.CFrame = HumanoidRootPart.CFrame * CFrame.new(0,-2.32,0)
		
		
		Aura1:Clone().Parent = RightArm
		Aura2:Clone().Parent = RightArm

		Aura1:Clone().Parent = LeftArm
		Aura2:Clone().Parent = LeftArm

		Aura1:Clone().Parent = Torso
		Aura2:Clone().Parent = Torso

		Aura1:Clone().Parent = LeftLeg
		Aura2:Clone().Parent = LeftLeg

		Aura1:Clone().Parent = RightLeg
		Aura2:Clone().Parent = RightLeg
		
		EyeRedLeft:Clone().Parent = AttachmentLeft

		EyeRedRight:Clone().Parent = AttachmentRight
		
		--Making a New Part
		local AwakenAura = Instance.new("Part")
		AwakenAura.Name = "AwakenAura"
		AwakenAura.Parent = HumanoidRootPart
		AwakenAura.Size = Vector3.new(1, 0.1, 1)
		AwakenAura.Massless = true
		AwakenAura.CanCollide = false
		
		AwakenAura:Clone()
		local weld = Instance.new("WeldConstraint")
		weld.Part0 = HumanoidRootPart
		weld.Part1 = AwakenAura
		weld.Part1.Anchored = false
		AwakenAura.CFrame = HumanoidRootPart.CFrame * CFrame.new(0,-2.32,0)
		AwakenAura.Parent = HumanoidRootPart
		weld.Parent = HumanoidRootPart -- NEED TO PARENT THE WELD TOO OR ITS GONNA FALL THROUGH THE MAP
		
		SpecialPartAttachment1.Parent = AwakenAura
		SpecialPartAttachment2.Parent = AwakenAura
		SpecialAttachment3.Parent = AwakenAura
		
		AuraBloom1:Clone().Parent = SpecialPartAttachment1
		AuraBloom2:Clone().Parent = SpecialPartAttachment2
		ShineRight:Clone().Parent = SpecialAttachment3
		Shineleft:Clone().Parent = SpecialAttachment3
		
end

function Module.UniqueAura(player, UserId, Character)
	
			Aura1.Color = ColorSequence.new(Color3.new(1, 1, 1))
			Aura2.Color = ColorSequence.new(Color3.new(0, 0, 0))
		EyeRedLeft.Color = ColorSequence.new(Color3.new(0.709804, 0.698039, 0.290196))
		EyeRedRight.Color = ColorSequence.new(Color3.new(0.709804, 0.698039, 0.290196))
			
			AuraBloom1.Color = ColorSequence.new(Color3.new(0.709804, 0.698039, 0.290196))
		AuraBloom2.Color = ColorSequence.new(Color3.new(0.709804, 0.698039, 0.290196))
			ShineRight.Color = ColorSequence.new(Color3.new(0.941176, 0.941176, 0.941176))
		Shineleft.Color = ColorSequence.new(Color3.new(0.941176, 0.941176, 0.941176))
		
	end




function Module.TurnOffAura(player, UserId, Character)
	if not Character then return end
	local AwakenPart = Character.HumanoidRootPart.AwakenAura

	 Character.Head.AttachmentLeft:Destroy()
	 Character.Head.AttachmentRight:Destroy()
	
	for _, Decendant in pairs(Character:GetDescendants()) do
		if  Decendant.ClassName == "ParticleEmitter" then
			Decendant:Destroy()
			AwakenPart:Destroy()
			
		end
		
	end
	
end```


return Module

If you want to “translate” the .find to the for loop it’d be something like this:

for loop here
    check here
end

code that runs if it isn't the user id

Why?:

The reason why your code didn’t work is that you aren’t checking if the id isn’t present, but rather if the id isn’t equal.

That is to say that you aren’t checking if the marble is present in the box but rather if all the marbles are the same as the one you are searching for.

That is the same as having a list of foods:

  • Hamburger
  • Pizza
  • Apple

And then asking yourself:
“Is this an Apple? No, it is a Hamburger” –runs else
“Is this an Apple? No, it is a Pizza” –runs else
“Is this an Apple? Yes, it is an Apple” –runs if

the above example is what you are doing, and this example is the one you want:
“Is there an Apple in this table? Yes there is an Apple in this table” –runs if once

More examples:

local t = {
	index1 = 1,
	index2 = 2,
	index3 = 3	
};

local desiredResult = x;
do --Your code
	for k,v in pairs(t) do --Iterates through every "marble" in the "box"
		if(v == desiredResult) then --Checks every "marble" in the "box"
			warn("Yes!");
		else
			warn("No!");
		end
	end
end

do --The correct code
	local found = false;
	for k,v in pairs(t) do
		if(v == desiredResult) then --Is this the correct "marble"?
			warn("Yes!");
			found = true; --Let us remember that we found the correct "marble"!
			break
		end
	end
	
	if(not found) then --Was the "marble" not found?
		warn("No!");
	end
end

If the desired result is 0:
image

If the desired result is 1:
image

1 Like

It would help if you created an instance of the module for each player. Right now variables are global and not tied to a player.

1 Like

Did I do it right? It still printed “No” even though it was the correct ID…


I also have a couple of questions.

  1. What are the brackets for around the (“If V == desiredresult”)?
  2. What does the ‘Break’ do?
  3. What exactly do I replace for desiredresult?

I also did this but it didn’t give me the unique aura

local playerID = {
	58508301,
	15454353, 
	2023345}


AuraRemote.OnServerEvent:Connect(function(player,  On)
	local character = player.Character
	local Humanoid = character.Humanoid
	local HumanoidRootPart = character.HumanoidRootPart
	if  On == true then 
		
		
local desiredresult = 58508301
		

		local found = false;

		for i, v in pairs(playerID) do
			if (v == desiredresult) then
				warn("Yes")
				AuraModule.UniqueAura(player.UserId,  character)	
				found = true
				break
			end
		end
		if (not found) then
			warn("No!")
			AuraModule.Aura(player, player.UserId,  character)
			task.wait(1)
			warn("Awakened")
		end```

Don’t compare v== playerID but rather v == player.UserId. You don’t want to compare the value with the table, only the value with the userid.

And for your questions:

  1. Many devs (including me) are used to code in other languages, adding brackets into if statements won’t change much how they work. It is just a style that many use including me, this also includes the ;. However, there is indeed a use case. For instance let’s say I want to compare the following:

Is var1 true and var2 0 or 1?

Rather than writing:

if var1 == true then
    if var2 == 0 or var2 == 1 then print("Nice!") end;
end

You can do:

if var1 == true and (var2 == 0 or var2 == 1) then
   print("Nice");
end

Essentially this goes to say that you can group conditions that couldn’t be grouped without parenthesis. Very similar to math where 1+1*2 is not the same as (1+1)*2

The reason why you would need to use parenthesis for the above condition is that if you didn’t it would check like this:
(var1 == true and var2 == 0) or var2 == 1


  1. Break “breaks” a loop. Useful to prevent duplicates. For instance let’s say I have the following loop:
local t = {1,2,4,5,1};

for k,v in pairs(t) do
    if(v == 1) then print("The value is one!") end;
end

In the above statement the print will print two times since there are two 1s in the table. If we want to prevent duplicates we can do this:

local t = {1,2,4,5,1};

for k,v in pairs(t) do
    if(v == 1) then
        print("The value is one!");
        break --We ensure the loop stops so it doesn't print two times
    end
end

Other examples:

local t = {1,2}
for k,v in pairs(t) do
    break
    print("This will never run!");
end
local t = {1,2,3,4,5}
for k,v in pairs(t) do
    print(k); --Prints 1,2,3
    if(k == 3) then
        print("I will not continue! I will stop at number 3!");
        break
    end
end

  1. Desired result is just a concept that I used to prove the theory of the for loop. You can delete it if you won’t use it anymore.
local playerID = {
	58508301,
	15454353, 
	2023345
}


AuraRemote.OnServerEvent:Connect(function(player,  On)
	local character = player.Character
	local Humanoid = character.Humanoid
	local HumanoidRootPart = character.HumanoidRootPart
	if(On == true) then
		print("Hey I printed!");
		
		local found = false;

		for i, v in pairs(playerID) do
			if(v == player.UserId) then
				warn("Yes")
				AuraModule.UniqueAura(player.UserId,  character)	
				found = true
				break
			end
		end
		
		if(not found) then
			warn("No!")
			AuraModule.Aura(player, player.UserId,  character)
			task.wait(1)
			warn("Awakened")
		end
	end	
end);

Can you verify if the above code prints “Hey I printed!”?

Also, I don’t know if you sent me the entire code. But there is no mention of AuraModule or AuraRemote. So just make sure the code isn’t erroring.

Yeah I still didn’t get the unique aura for some reason /:, I can send you the module script right now

Module Script:

local replicatedstorage = game:GetService("ReplicatedStorage")
local aura = replicatedstorage.Aura
local Aura1 = aura.Aura1Effect:Clone()
local Aura2 = aura.Embers:Clone()
local EyeRedLeft = aura:WaitForChild("ParticleEmitterRedLeft")
local EyeRedRight = aura:WaitForChild("ParticleEmitterRedRight")
local Shineleft = aura.shineLeft:Clone()
local ShineRight = aura.shineRight:Clone()
local AuraBloom1 = aura.Aura1Bloom:Clone()
local AuraBloom2 = aura.AuraBloom2:Clone()





local playerID = {
	58508301,
	15454353, 
	2023345

}


local Module = { }
--(player, player.UserId,  character)
function Module.Aura(player, UserId,Character)

	

		local Head = Character.Head
		local RightArm = Character["Right Arm"]
		local LeftArm = Character["Left Arm"]
		local LeftLeg = Character["Left Leg"]
		local RightLeg = Character["Right Leg"]
		local Torso = Character.Torso
		local HumanoidRootPart = Character.HumanoidRootPart
		--Attachments
		
		local AttachmentLeft = Instance.new("Attachment")
		AttachmentLeft.Position = Vector3.new(0.204, 0.221, -0.6)
		AttachmentLeft.Name = "AttachmentLeft"
		AttachmentLeft.Parent = Head
		

		local AttachmentRight = Instance.new("Attachment")
		AttachmentRight.Position = Vector3.new(-0.192, 0.216, -0.6)
		AttachmentRight.Name = "AttachmentRight"
		AttachmentRight.Parent = Head
		
		
		local SpecialPartAttachment1 = Instance.new("Attachment")
		--SpecialPartAttachment1.CFrame = HumanoidRootPart.CFrame * CFrame.new(0,-2.32,0)
		SpecialPartAttachment1.Name = "SpecialPartAttachment1"
		
		
		local SpecialPartAttachment2 = Instance.new("Attachment")
		--SpecialPartAttachment2.CFrame = HumanoidRootPart.CFrame * CFrame.new(0,-2.32,0)
		SpecialPartAttachment2.Name = "SpecialPartAttachment1"
		
		
		local SpecialAttachment3 = Instance.new("Attachment")
	SpecialAttachment3.Name = "SpecialAttachment3"
	
	local SpecialAttachment4 = Instance.new("Attachment")
	SpecialAttachment4.Name = "SpecialAttachment4"
	
	
		--SpecialAttachment3.CFrame = HumanoidRootPart.CFrame * CFrame.new(0,-2.32,0)
		
		
		Aura1:Clone().Parent = RightArm
		Aura2:Clone().Parent = RightArm

		Aura1:Clone().Parent = LeftArm
		Aura2:Clone().Parent = LeftArm

		Aura1:Clone().Parent = Torso
		Aura2:Clone().Parent = Torso

		Aura1:Clone().Parent = LeftLeg
		Aura2:Clone().Parent = LeftLeg

		Aura1:Clone().Parent = RightLeg
		Aura2:Clone().Parent = RightLeg
		
		EyeRedLeft:Clone().Parent = AttachmentLeft

		EyeRedRight:Clone().Parent = AttachmentRight
		
		--Making a New Part
		local AwakenAura = Instance.new("Part")
		AwakenAura.Name = "AwakenAura"
		AwakenAura.Parent = HumanoidRootPart
		AwakenAura.Size = Vector3.new(1, 0.1, 1)
		AwakenAura.Massless = true
		AwakenAura.CanCollide = false
		
		AwakenAura:Clone()
		local weld = Instance.new("WeldConstraint")
		weld.Part0 = HumanoidRootPart
		weld.Part1 = AwakenAura
		weld.Part1.Anchored = false
		AwakenAura.CFrame = HumanoidRootPart.CFrame * CFrame.new(0,-2.32,0)
		AwakenAura.Parent = HumanoidRootPart
		weld.Parent = HumanoidRootPart -- NEED TO PARENT THE WELD TOO OR ITS GONNA FALL THROUGH THE MAP
		
		SpecialPartAttachment1.Parent = AwakenAura
		SpecialPartAttachment2.Parent = AwakenAura
		SpecialAttachment3.Parent = AwakenAura
		
		AuraBloom1:Clone().Parent = SpecialPartAttachment1
		AuraBloom2:Clone().Parent = SpecialPartAttachment2
		ShineRight:Clone().Parent = SpecialAttachment3
		Shineleft:Clone().Parent = SpecialAttachment3
		
end

function Module.UniqueAura(player, UserId, Character)
	
			Aura1.Color = ColorSequence.new(Color3.new(1, 1, 1))
			Aura2.Color = ColorSequence.new(Color3.new(0, 0, 0))
		EyeRedLeft.Color = ColorSequence.new(Color3.new(0.709804, 0.698039, 0.290196))
		EyeRedRight.Color = ColorSequence.new(Color3.new(0.709804, 0.698039, 0.290196))
			
			AuraBloom1.Color = ColorSequence.new(Color3.new(0.709804, 0.698039, 0.290196))
		AuraBloom2.Color = ColorSequence.new(Color3.new(0.709804, 0.698039, 0.290196))
			ShineRight.Color = ColorSequence.new(Color3.new(0.941176, 0.941176, 0.941176))
		Shineleft.Color = ColorSequence.new(Color3.new(0.941176, 0.941176, 0.941176))
		
	end




function Module.TurnOffAura(player, UserId, Character)
	if not Character then return end
	local AwakenPart = Character.HumanoidRootPart.AwakenAura

	 Character.Head.AttachmentLeft:Destroy()
	 Character.Head.AttachmentRight:Destroy()
	
	for _, Decendant in pairs(Character:GetDescendants()) do
		if  Decendant.ClassName == "ParticleEmitter" then
			Decendant:Destroy()
			AwakenPart:Destroy()
			
		end
		
	end
	
end


return Module

Question, here I can see it working. Is it just not showing or what is going on? And another thing is I can’t fully test the module since I lack the instances to do it the aura in ReplicatedStorage for example

Yeah so The unique aura is not showing, but the regular aura shows. I don’t think its the actual aura particles because The unique aura is just a diffrent color from the regular aura.

Video:video 28 - YouTube