Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

A problem with an If Statement? [SOLVED]

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

3 comments

0

I noticed i made the print say "got past the function" but its an if statement but same thing these days lol

1

If statements only run once, they don't run whenever the condition becomes true later on.

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.

2 answers

✓ Accepted answer

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

2 comments

0

I realize there are a few mistakes in my answer, if am fixing those now.

0

Done.

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

1 comment

0

didn't work sorry

This discussion is preserved as it was. New answers, comments, and votes are closed.