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
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
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