Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why Doesnt Script Check That Boolean Value Is True?

Asked by 1 year ago

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

Log in to vote
0
Answered by
NykoVania 231 Moderation Voter
1 year ago

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

0
alright but i need an example JmoneyPlayzOfficial 49 — 1y
Ad
Log in to vote
0
Answered by 1 year ago

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
0
it didnt work, would it work if instead of a boolvalue i insert a number value, 0 meaning false and 1 meaning true? JmoneyPlayzOfficial 49 — 1y
0
uhmm that's how boolvalues work... T3_MasterGamer 2189 — 1y
0
if it's a number value you can set it to 2, which is neither 0 nor 1 T3_MasterGamer 2189 — 1y
0
so boolvalue is preferred T3_MasterGamer 2189 — 1y
0
are you sure you're changing the value in server? maybe ur changing it in the cliennt T3_MasterGamer 2189 — 1y

Answer this question