If statement not working on a for loop

  1. What do you want to achieve?
    I am trying to loop trought each objects in the workspace.

  2. What is the issue? Include screenshots / videos if possible!
    The problem is that the if statement is not working, its supposed to print every
    “Right Leg” and “Left Leg” models.

  3. What solutions have you tried so far?

--[[
Frames positions:
Opened: {0.34, 0},{0.327, 0}
Closed : {0.34, 0},{1.3, 0}
]]--
-- Made by Beez_up
-- Some npc's have a click detector on and are'nt suposed to have one?
-- Add the npc's name here:
local blacklist = {'Enter npc name that you dont want to work.'}
-- Don't touch from here



local ishirt
local mps = game:GetService("MarketplaceService")
local plr = game.Players.LocalPlayer
local char = script.Parent.WeldFrame.Character.Char
local frame = script.Parent.WeldFrame
local id
local template
local function clearCloths()
	char.Shirt.ShirtTemplate = ''
	char.Pants.PantsTemplate = ''
end
local function prompt(id)
	mps:PromptPurchase(plr,id)
end
local frame =script.Parent.WeldFrame
-- Function that returns true if the argument passed is a player
local function isPlayer(char)
	local name = char.Name
	if not char:FindFirstChild'Humanoid' then return end
	if game.Players:FindFirstChild(name) then
		return true
	elseif table.find(blacklist,char.Name) then
		warn('\''..char.Name .. '\' is black listed!')
		return true
	else
		return false
	end
end
local function open()
	frame:TweenPosition(UDim2.new(0.34, 0,0.327, 0),Enum.EasingDirection.Out,Enum.EasingStyle.Bounce,.4,false,nil)
end
local function close()
	frame:TweenPosition(UDim2.new(0.34, 0,1.3, 0),Enum.EasingDirection.Out,Enum.EasingStyle.Bounce,.4,false,nil)
end
for _,value in pairs(workspace:GetDescendants()) do
	if value:FindFirstChild('Left Leg') then -- Not working from there
		if not value:FindFirstChild("Torso") then
			if value:FindFirstChild("Right Leg") then
				print(value.Name)
			end
		end
	end
end
frame.Close.MouseButton1Up:Connect(close)
frame["Buy Text"].MouseButton1Up:Connect(function()
	mps:PromptPurchase(plr,tonumber(id))
end)
frame["Try On Text"].MouseButton1Up:Connect(function()
	game:GetService("ReplicatedStorage").Events.Wear:FireServer(template,ishirt )
end)

Thanks for reading!

Is this in a LocalScript? What exactly are you trying to do with this script?

There’s a FindFirstChild without brackets in the first few lines of the IsPlayer function.

I believe brackets are imperative.

Its a local script. (30 charsss)

It’s probably because you have all the if statements nested, making it really hard to understand what you’re trying to do. Are you trying to print every object that contains a left leg and right leg? Or print every thing that is named left leg and right leg?

1 Like

I am making a homestore, and in that homestore theres leg only npc’s.

The description confuses me. (30 chars)

Yeah, i tryied that but did’nt worked.

	if not value:FindFirstChild("Torso") and value:FindFirstChild("Left Leg") and value:FindFirstChild("Right Leg") then
		print(value.Name)
	end

Any errors like at all? (30 chars)

No, no errors (30 charrrssssssss)

Are you sure that the items you want the script to find have all their parts named properly?

1 Like

I don’t know if its helpful or not but i added an else statement and it printed x1110 different names

Will it work if they all have the same name?

Can you post a screenshot of how the leg models appear in the object hierarchy?

They are all parented to workspace

I understood that the problem was that the left legs were not loaded. However, I appreciate your help!