Or Statements Not Working?

i was just experimenting with continue end and other things when i discovered a weird bug

or statements dosent seem to be working

basically i was placing a part named “someone” since the code fires when part in workspace named “someone” or “someone else” existed

but when i make another part named “someone else” well it dosent fire the code

heres the code:

while task.wait() do 
	if workspace:WaitForChild("someone") or workspace:WaitForChild("someone else") then
		print("found someone")
	else
		continue
	end
end

and yes no error codes except infinite yield possible on

are you renaming the object on the CLIENT?
When I rename a part on the server it prints like normal.

Unless you’re using a localscript and not a serverscipt

first of all yes i did it on the server and secend of all its a server script placed on serverscriptservice

Ok now that I look at it I think it’s simply a logic error. The script should be

while task.wait() do 
	if workspace:FindFirstChild("someone") or workspace:FindFirstChild("someone else") then
		print("found someone")
	else
		continue
	end
end

FindFirstChild() checks if the object exists and if not returns false, allowing the script to continue. I assume when you use WaitForChild() one of the statements doesn’t match, causing the script to look for that object forever??

It’s also not needed to use WaitForChild() in a server script (in many cases, sometimes maybe) because everything should already load on the server

oh it actually works. i thought waitforchild waits for it since it dosent exist yet

WaitForChild() does infact wait for an object to exist but in this case you’re using it in a loop so it should be FindFirstChild() because you’re looping until you find the object, you should use WaitForChild() in probably only variables for example

local Hi = workspace:WaitForChild("hi")

The way you made the script when it loops once when it tries to waitforchild It never finds it causing the loop to not loop

thanks i didnt really know that. probbably gonna be useful on future projects

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.