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 3 years ago
Edited 3 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.

if workspace:FindFirstChild("WoodPlank") == nil and workspace:FindFirstChild("WoodPlank1") == nil then
    print("got past function")
    wait(1)
    print("got past wait")
    Controls:Disable()
    print("got past the control disable")
    HRP.CFrame = CFrame.new(Vector3.new(547.39, 5.61, -818.99))
    print("got past the TP")
    setText("Good job! Now go inside and see how big and... wait a minute it's empty?")
    Next3.Visible = true
    print("got past the whole thing")
end
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 — 3y
1
If statements only run once, they don't run whenever the condition becomes true later on. zboi082007 270 — 3y
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 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 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:

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

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

local num = 2

while 2 + num == 4 do
wait(0)
num = 1
if workspace:FindFirstChild("WoodPlank") == nil and workspace:FindFirstChild("WoodPlank1") == nil then
    print("got past function")
    wait(1)
    print("got past wait")
    Controls:Disable()
    print("got past the control disable")
    HRP.CFrame = CFrame.new(Vector3.new(547.39, 5.61, -818.99))
    print("got past the TP")
    setText("Good job! Now go inside and see how big and... wait a minute it's empty?")
    Next3.Visible = true
        print("got past the whole thing")
    end
    end
0
didn't work sorry MarcTheRubixQb 153 — 3y

Answer this question