If condition met but output says otherwise?

Scripting might not just be for me

local Assets = RS:WaitForChild("Assets")

	local GUI = Assets:WaitForChild("GUIS")
	local GUIS = GUI:GetChildren()
	print(GUIS)

	for _, v in ipairs(GUIS) do
		print(v)
		print(itemName)
		if v == itemName then
			local clone = v:Clone()
			clone.Parent = player:WaitForChild("PlayerGUI").InvScreenGUI.InvFrame.Storage
			print("should clone")
		else
			print("gui does not exist")
		end
	end

v and itemName print the exact same thing, i tried converting them both to strings just in case but it still only prints “gui does not exist”. wth am i doing wrong i dont want to think anymore

You need to GetChildren on GUIS to have a table to run your for loop against:

for _, v in ipairs(GetChildren (GUIS)) do

The above response just makes up a function…?


I believe itemName is in the form of a string. To account for this, you should use v.Name instead of v. (tostring(v) returns nil, hence why it didn’t work earlier).
i.e.

if v.Name == itemName then
1 Like
local Assets = RS:WaitForChild("Assets")
local GUI = Assets:WaitForChild("GUIS")
local GUIS = GUI:GetChildren()
print(GUIS)

for _, v in ipairs(GUIS) do
    print(v)
    print(v.Name) -- Print the name of the GUI instance
    print(itemName) -- Print the itemName to check its value
    if v.Name == itemName then
        local clone = v:Clone()
        clone.Parent = player:WaitForChild("PlayerGUI").InvScreenGUI.InvFrame.Storage
        print("should clone")
    else
        print("gui does not exist")
    end
end
1 Like

If the issue persists, print additional debug:

print("Type of v.Name:", typeof(v.Name))
print("Type of itemName:", typeof(itemName))
1 Like

Here, you are comparing an Instance v with a string itemName.
Do v.Name == itemName instead, that should fix it.

1 Like

This was the first person to point out mistake so I will give the solution to him, thanks for everyone who replied for my silly mistake :slight_smile:

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