I want these doors to add 1 to the value when they are a specific colour, when it has all been added up to 3 then it will print “Greater”
The problem is that whenever the doors are a specific colour, and the values have been added up to 3, it still hasn’t been printed. I’m not sure if the values were added up correctly.
local codedoor = game.Workspace.CodeDoor.Door
local codedoor2 = game.Workspace.CodeDoor2.Door
local value = 1
if codedoor.Color == Color3.new(0.333333, 1, 0) then
value = value + 1
end
if codedoor2.Color == Color3.new(0.333333, 1, 0) then
value = value + 1
end
if value >= 3 then
print("Greater")
end
just saying, wouldnt you want to constantly check if the door colours are changed to something else? cause someone could just switch through all whatever colours and eventually get it
and i think this could be cuz this is being run once, so its passing the first two checks but the third check already failed before the requirement was met
Like Exo said, your code is being read from top to bottom as soon as it runs. An if statement does not constantly check the value if it has changed. It will check when the statement has been read, return a value (in this case; false, not running the function) and pass to the next line.
If you want to check the door and keep it performance friendly unlike a while .. do loop, you can utilize the .Changed event. Then you can check if what has changed is the color, and check if the color has been changed to the desired color you want, and then run the function.
The code is running once, you should put the if statement in a loop like this:
while wait() do
if value >= 3 then
print("Greater")
end
end
Next time, always put if statements in a loop if you want to check a value if it’s true or not, because the code you made told the script to check the value before the game even runs!
Your Code is ran top to bottom only once when it is initalized. you need to keep checking the condition constantly. to do so you can use a while loop or a little bit more advanced technique which is
game:GetService("RunService").Heartbeat:Connect(function()
--Do stuff here / it will be updated at 60fps.
end)
So final code would look something like
local codedoor = game.Workspace.CodeDoor.Door
local codedoor2 = game.Workspace.CodeDoor2.Door
local value = 1
if codedoor.Color == Color3.new(0.333333, 1, 0) then
value += 1
end
if codedoor2.Color == Color3.new(0.333333, 1, 0) then
value += 1
end
game:GetService("RunService").Heartbeat(function()
if value >= 3 then
print("Greater")
end
end)