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

Why won't my script detect if the variables are true and execute if it is?

I'm trying to make a gravity falls reference in an elevator where you can press the buttons in a certain order and when it does, it changes a value to be true so the next floor is the gravity falls floor.

However my script just won't work, the first print I provided in the script works but the "if" seems to be like "yeah nope it's not true so not doing the thing" even though it's true?? I don't really know what to try here to fix it so please help!

There're also no errors.

Edit 1: I did some more testing and I realized the script thinks that the ButtonPress values stay false even if I change them to true. I realized this when I changed in the script that instead of true, I made it false. And it works even if I press the button or don't.

(Excuse the messy code)

local Keypad = script.parent.parent.parent
local EValues = game.ServerStorage.ElevatorValues
local B1 = Keypad["1"]["1"].ButtonPress.Value == true
local B2 = Keypad["2"]["2"].ButtonPress.Value == true
local B4 = Keypad["4"]["4"].ButtonPress.Value == true
local B7 = Keypad["7"]["7"].ButtonPress.Value == true
local B8 = Keypad["8"]["8"].ButtonPress.Value == true

local B3 = Keypad["1"]["1"].ButtonPress.Value == false
local B5 = Keypad["2"]["2"].ButtonPress.Value == false
local B6 = Keypad["4"]["4"].ButtonPress.Value == false
local B9 = Keypad["7"]["7"].ButtonPress.Value == false
local B10 = Keypad["8"]["8"].ButtonPress.Value == false
local BBell = Keypad["1"]["1"].ButtonPress.Value == false
local BHelp = Keypad["2"]["2"].ButtonPress.Value == false
local BClose = Keypad["4"]["4"].ButtonPress.Value == false

local cooldown = false
local part = script.parent

part.ClickDetector.MouseClick:Connect(function()
	print("Checking if Gravity Falls Reference sequence was pushed correctly.")
	if cooldown == false and B1 and B2 and B4 and B7 and B8 and B3 and B5 and B6 and B9 and B10 and BBell and BHelp and BClose then
		EValues.GravityFalls.Value = true
		print("Someone got the Gravity Falls Reference! Wohoo!!")
		cooldown = true
		wait(1) -- testing purposes, once done change to 1800
		cooldown = false
	end
end)

1 answer

✓ Accepted answer

I think the problem is that you aren't updating any of your values, so they are just staying static, you could fix this by updating the values before checking them, something like:

local Keypad = script.parent.parent.parent
local EValues = game.ServerStorage.ElevatorValues
local B1 = Keypad["1"]["1"].ButtonPress.Value == true
local B2 = Keypad["2"]["2"].ButtonPress.Value == true
local B4 = Keypad["4"]["4"].ButtonPress.Value == true
local B7 = Keypad["7"]["7"].ButtonPress.Value == true
local B8 = Keypad["8"]["8"].ButtonPress.Value == true

local B3 = Keypad["1"]["1"].ButtonPress.Value == false
local B5 = Keypad["2"]["2"].ButtonPress.Value == false
local B6 = Keypad["4"]["4"].ButtonPress.Value == false
local B9 = Keypad["7"]["7"].ButtonPress.Value == false
local B10 = Keypad["8"]["8"].ButtonPress.Value == false
local BBell = Keypad["1"]["1"].ButtonPress.Value == false
local BHelp = Keypad["2"]["2"].ButtonPress.Value == false
local BClose = Keypad["4"]["4"].ButtonPress.Value == false

local cooldown = false
local part = script.parent

local function UpdateValues()
	B1 = Keypad["1"]["1"].ButtonPress.Value == true
	B2 = Keypad["2"]["2"].ButtonPress.Value == true
	B4 = Keypad["4"]["4"].ButtonPress.Value == true
	B7 = Keypad["7"]["7"].ButtonPress.Value == true
	B8 = Keypad["8"]["8"].ButtonPress.Value == true

	B3 = Keypad["1"]["1"].ButtonPress.Value == false
	B5 = Keypad["2"]["2"].ButtonPress.Value == false
	B6 = Keypad["4"]["4"].ButtonPress.Value == false
	B9 = Keypad["7"]["7"].ButtonPress.Value == false
	B10 = Keypad["8"]["8"].ButtonPress.Value == false
	BBell = Keypad["1"]["1"].ButtonPress.Value == false
	BHelp = Keypad["2"]["2"].ButtonPress.Value == false
	BClose = Keypad["4"]["4"].ButtonPress.Value == false
end

part.ClickDetector.MouseClick:Connect(function()
	print("Checking if Gravity Falls Reference sequence was pushed correctly.")
	UpdateValues()
	if cooldown == false and B1 and B2 and B4 and B7 and B8 and B3 and B5 and B6 and B9 and B10 and BBell and BHelp and BClose then
		EValues.GravityFalls.Value = true
		print("Someone got the Gravity Falls Reference! Wohoo!!")
		cooldown = true
		wait(1) -- testing purposes, once done change to 1800
		cooldown = false
	end
end)

I'm not 100% confident this will work, since I don't have access to the rest of your game, but it should work if I understand the problem.

7 comments

0

This still didn't work sadly :(, although I did notice something wrong I did. I forgot to change the later numbers B3 and B5 and the rest to their actual numbers. You can see this if you look after Keypad, it still says 1 and 2. I thought this was the problem so I fixed it but it still didn't work.

0

Here, I decided to upload the required models to roblox for you to check it out. Put the Elevator Values folder inside ServerStorage https://web.roblox.com/catalog/7065892646/Elevator-Keypad

0

oh i forgot to say, after you press the buttons in the correct order. Press the Open elevator button and it checks to see if you pushed the buttons correctly. What should happen is it says "Yay you did it right" in console and change the GravityFalls value to true inside of the Elevator Values folder.

0

I will check it out and come back once/if I find something wrong

0

Never mind! I figured out the answer. You were right about the static values, except you did it wrong. I won't explain what you did wrong since it's complicated but thanks for helping me find the answer!

0

Nvm I'll just say what you did wrong, I moved the local variables inside of the clickdetector function similar to what you did with the UpdateValues() except that doesn't work since the variables were local so it changed nothing.

0

oh, i actually found a different solution that worked with my script, but nice problem solving, and thanks for telling me how you made it work for you!

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