"or" function not working as intended?

so i have a code here,

local part = game.Workspace.Select or game.ReplicatedStorage.Select:Clone()

so the error said it dosn’t exist in workplace, which it dosn’t. but isn’t “or” functions supposed to go to the alternative if the first one dosn’t work? why does it not go to the function behind it?

Use workspace:FindFirstChild(‘Select’) instead of workspace.Select. The former returns nil if the instance isn’t found, the latter will error if the instance isn’t found.

Also or is an operator not a function. Essentially it works like so, so given the following:

a or b or c

It will evaluate a, if a is truthy (aka not nil or false), it will return a,
else it will evaluate b. If b is truthy it will return b,
else it will evaluate c. If c is truthy it will return c,
else it will return false.

If any of the evaluations cause an error, it will cause an error in the console as normal and the thread will terminate.


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