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

Problems With My If Statement Returning True When It Shouldn't?

Even Though An Object Doesn't Have The Name Of Anything In The If Statement It Comes Back As If The If Statement Were True. Does Anyone Know How To Fix This?

   while true do
        wait()
			local t = (workspace.Items:GetChildren())
for index, value in ipairs(t) do
    if value == "Rokakaka Fruit" or "Arrow" or "Money" or "Meme Diary" or "Kujo Jotaro Cap" or "Aja Mask" or "Scroll" then
			        print(value)
		else
			print("ITEM FOUND")
        return index
    end
end
        end

1 comment

0

line 4 "ipairs?"

2 answers

✓ Accepted answer

You need to create a new condition each or and and, you can't just do value1 or value2, or it will return true, as strings aways are true

   while true do
        wait()
            local t = (workspace.Items:GetChildren())
for index, value in ipairs(t) do
    if value == "Rokakaka Fruit" or value == "Arrow" or value == "Money" or value == "Meme Diary" or value == "Kujo Jotaro Cap" or value == "Aja Mask" or value == "Scroll" then
                    print(value)
        else
            print("ITEM FOUND")
        return index
    end
end
        end

2 comments

0

w in workspace is still Lowercase ... Make it Uppercase "Workspace" line 3

0

actally it should be lower case

you can also just make it into a table to make it neater and easier to add to / organize

local items = {"fruit1","fruit2","fruit3"}
local t = workspace.Items:GetChildren()

for index, value in ipairs(t) do
	for _,v in pairs(items) do
		if value.Name == v then
			--do stuff
		end
	end
end

untested so sorry for any mistakes

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