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

Why Doesnt Script Check That Boolean Value Is True?

im making a fnaf power system where there's a tick value that when goes over 100 it goes back to 0 and takes away a bit from the power (in another script), I want to make it that the more stuff you use, the tick goes down faster, I tried to make it but it stayed the same. can someone help me please

local hallwayLight = workspace.HallwayLight["IsHallwayLightUsed?"]
local leftDoor = workspace.LeftDoor["IsLeftDoorClosed?"]
local leftLight = workspace.LeftDoor["IsLeftDorrLightOn?"]
local rightDoor = workspace.RightDoor["IsRightDoorClosed?"]
local rightLight = workspace.RightDoor["IsRightDoorLightOn?"]

while hallwayLight == true do 
		wait(0.3)
		script.Parent.Value += 1
	end
end

while leftDoor == true do 
		wait(0.3)
		script.Parent.Value += 1
	end
end

while leftLight == true do 
	wait(0.3)
		script.Parent.Value += 1
	end
end

while rightDoor == true do 
		wait(0.3)
		script.Parent.Value += 1
	end
end

while rightLight == true do 
	wait(0.3)
end
end

2 answers

The while loop doesn't constantly check if something equals true, it only checks it at that moment, try using .Changed or something

1 comment

0

alright but i need an example

When you put lines of code after a loop (especially the while loop), it won't run because the code will get stuck in that loop forever. Maybe you can use break but I'm not sure if it will only break the loop only or stop the entire script.

Try making one huge loop and inside it, make multiple conditions for each of them that if one of them has a Value of true (i assume they're all BoolValue) it will increase the Value of script.Parent.

local hallwayLight = workspace.HallwayLight["IsHallwayLightUsed?"]
local leftDoor = workspace.LeftDoor["IsLeftDoorClosed?"]
local leftLight = workspace.LeftDoor["IsLeftDorrLightOn?"]
local rightDoor = workspace.RightDoor["IsRightDoorClosed?"]
local rightLight = workspace.RightDoor["IsRightDoorLightOn?"]

while true do
	task.wait(0.3)
	
	if hallwayLight.Value == true then
		script.Parent.Value += 1
	end
	
	if leftDoor.Value == true then
		script.Parent.Value += 1
	end
	
	if leftLight.Value == true then
		script.Parent.Value += 1
	end
	
	if rightDoor.Value == true then
		script.Parent.Value += 1
	end
	
	if rightLight.Value == true then
		script.Parent.Value += 1
	end
end

5 comments

0

it didnt work, would it work if instead of a boolvalue i insert a number value, 0 meaning false and 1 meaning true?

0

uhmm that's how boolvalues work...

0

if it's a number value you can set it to 2, which is neither 0 nor 1

0

so boolvalue is preferred

0

are you sure you're changing the value in server? maybe ur changing it in the cliennt

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