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

A problem with an If Statement? [SOLVED]

Asked by 4 years ago
Edited 4 years ago

So in my game there is a beginning tutorial and in the middle of it you are meant to break down 2 wood planks to get past and they are meant to get destroyed, they do get destroyed but the statement still won't go through. now don't worry about the inside of the if statement but what is happening is that nothing will print which means it won't go through. No errors about this in my output. Please help.

01if workspace:FindFirstChild("WoodPlank") == nil and workspace:FindFirstChild("WoodPlank1") == nil then
02    print("got past function")
03    wait(1)
04    print("got past wait")
05    Controls:Disable()
06    print("got past the control disable")
07    HRP.CFrame = CFrame.new(Vector3.new(547.39, 5.61, -818.99))
08    print("got past the TP")
09    setText("Good job! Now go inside and see how big and... wait a minute it's empty?")
10    Next3.Visible = true
11    print("got past the whole thing")
12end
0
I noticed i made the print say "got past the function" but its an if statement but same thing these days lol MarcTheRubixQb 153 — 4y
1
If statements only run once, they don't run whenever the condition becomes true later on. zboi082007 270 — 4y
0
so would i make the if statement go how many times. I can make a for loop because i tried a while true do loop but i don't want that because then it goes over and over but it has to go once. MarcTheRubixQb 153 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

I see your issue here.
An 'if statement' runs once when the script loads, so it's not checking WHEN the wood is nil, it's simply checking IF wood is nil.

To solve this issue, you can simply wrap the whole thing in a 'while loop'

Code Sample:

01while wait() do
02    if workspace:FindFirstChild("WoodPlank") == nil and workspace:FindFirstChild("WoodPlank1") == nil then
03        print("got past function")
04        wait(1)
05        print("got past wait")
06        Controls:Disable()
07        print("got past the control disable")
08        HRP.CFrame = CFrame.new(Vector3.new(547.39, 5.61, -818.99))
09        print("got past the TP")
10        setText("Good job! Now go inside and see how big and... wait a minute it's empty?")
11        Next3.Visible = true
12        print("got past the whole thing")
13    end
14break -- This is here to make sure the 'while loop' stops when the 'if statement' is over.
15end
0
I realize there are a few mistakes in my answer, if am fixing those now. ThatDevTim 188 — 4y
0
Done. ThatDevTim 188 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

You could use while loop and you can stop it once the num will be 1

01local num = 2
02 
03while 2 + num == 4 do
04wait(0)
05num = 1
06if workspace:FindFirstChild("WoodPlank") == nil and workspace:FindFirstChild("WoodPlank1") == nil then
07    print("got past function")
08    wait(1)
09    print("got past wait")
10    Controls:Disable()
11    print("got past the control disable")
12    HRP.CFrame = CFrame.new(Vector3.new(547.39, 5.61, -818.99))
13    print("got past the TP")
14    setText("Good job! Now go inside and see how big and... wait a minute it's empty?")
15    Next3.Visible = true
16        print("got past the whole thing")
17    end
18    end
0
didn't work sorry MarcTheRubixQb 153 — 4y

Answer this question