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

How do I get local tab to function as several variables in one so bacon.Value works?

local Chee = script.Parent.Parent.PlayerGui:WaitForChild("ScreenGui"):WaitForChild("Frame"):WaitForChild("TextBox")

local bacon = script.Parent.Parent:WaitForChild("Folder"):WaitForChild("Timer")

local bee = script.Parent.Parent:WaitForChild("Folder"):WaitForChild("JailBreak")

local tab =60, 120, 180, 240,  300,  360,  420,  480,  540, 600

function Activate()
	for i=1,bacon.Value do
wait(1)
		bacon.Value = bacon.Value - 1
		Chee.Text = bacon.Value
do Chee.Text = bacon.Value
if bacon.Value == 0 then
end
end
	end
	end

wait(0.2)
bacon.Changed:connect(function()
   if bee.Value == true and Chee.Text == "0" and bacon.Value == table then
		print(bacon.Value)
	Activate()
else 
	end
	
end)


How do I get "local tab" To act as several variables, so that when bacon.value changes to one of the 10 variables listed in local tab, It activates Activate?

Also bonus question: how do you put a gui in a weapon?

1 answer

✓ Accepted answer

Tables

Based on your naming conventions, I guess you sort of have an idea of what you're going for, but never bothered to actually learn quite how tables work.

First, we're going to convert your tab to an actual table.

local tab = {60, 120, 180, 240,  300,  360,  420,  480,  540, 600}

Then, for ease of use, we're going to convert it to a dictionary where the values become the keys. This means that you can check by the hash instead of iterating (In simple terms, it just makes it easier and you don't have to worry about why)

do
  local t = {};
  for i=1,#tab do
    t[tab[i]] = true
  end
  tab = t
end

And then we're going to check whether bacon.Value can be found within tab

if tab[bacon.Value] then
  -- Yes
end

Alternative solution

You can also solve this mathematically; All of the values in tab are multiples of 60. You can check whether bacon.Value is a multiple of 60 by using the modulus operator like so:

if (bacon.Value % 60) == 0 then
  -- It's a multiple of 60. Not sure about it being a boy.
end

1 comment

0

Dang it, I was still asleep.

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