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

Trying To Find True In IF Statement?

I Am Trying To Change A TextLabel If Its True Without Using A Lot Of IF Statements

local Slot1 = 1

if Slot1 or Slot2 or Slot3 or Slot4 or Slot5 or Slot6 == 1 then
	ShopFrame.Slot1.ItemName.Text = "TBD"
	ShopFrame.Slot1.Price.Text = "TBD "
end

I want to make it so I can change Slot1 doesn't get changed.

Hope I explained enough

1 comment

0

if, elseif

2 answers

✓ Accepted answer

Rather than repeating the same thing 6 times, you could use an array than loop through that. What this does instead of having variables named Slot1, Slot2, Slot3, Slot4, etc, you have an array called Slots, and to reference each slot you can do Slot[1], and then use the for loop shown below to check if any of the slots equal true.

local Slots = {1,1,1,1,1,1}

for i,slotNum in pairs(Slots) do
	if slotNum == 1 then
		ShopFrame.Slot1.ItemName.Text = "TBD"
		ShopFrame.Slot1.Price.Text = "TBD "
		break
	end
end

Here is one solution you can try, It's pretty simple, should definitely work. :)

if Slot1 == 1 or Slot2 == 1 or Slot3 == 1 or Slot4 == 1 or Slot5 == 1 or Slot6 == 1 then
 	ShopFrame.Slot1.ItemName.Text = "TBD"
	ShopFrame.Slot1.Price.Text = "TBD"
end

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