"If Then" statement not checking correctly

Hello, I’ve noticed an error with my If then Statement, inside of a tool. I will give the full script if it is needed,

		rock.Material = Enum.Material.Sand
		rock.Color = Color3.new(0.968627, 1, 0.752941)
		rock.Parent = tool
		rock.Size = Vector3.new(math.random(1,2),math.random(1,2),math.random(1,2))
		tool.Name = 'Ancient Sand'
		tool.Parent = workspace
		tool:PivotTo(handleclone.CFrame)
		handleclone.Transparency = 1
		Remove()
	elseif Player:WaitForChild('Body').Value == 'Moon' or 'Quaerthunder' or 'Kernol' or 'Mercury' or 'Sector 1b' then
		rock.Material = Enum.Material.Glass
		rock.Shape = 1
		rock.Color = Color3.new(0, 0, 0)
		rock.Parent = tool
		rock.Size = Vector3.new(math.random(1,2),math.random(1,2),math.random(1,2))
		tool.Name =  'Dark Glass'
		tool.Parent = workspace
		tool:PivotTo(handleclone.CFrame)
		handleclone.Transparency = 1
		Remove()

	else
		Remove()
		warn('Is not a planet that generates rocks with an explosive charge...')
	end

Main Problem: See how it says if Player:WaitForChild('Body').Value == 'Persianta' or 'Titaniturn' then? even if the Body value isn’t Persianta or Titaniturn, It will still generate sand, or glass (the elseif statement.)

I’ve tried rearranging this if statement, but it won’t change the outcome.

That’s not how the or thing works.
Currently, the if statement is checking if either of the following evaluate to true:

player:WaitForChild("Body").Value == "Persianta"

or

"Titaniturn"

Strings always evaluate to true, so it’s equivalent to

player:WaitForChild("Body").Value == "Persiantat" or true

which is always going to be true, hence the if statement runs the code within.


The two main ways of making it work how you want is to either add the .Value == “” bit to every value you wish to check, or use table.find.

Based on other parts of your code, I would recommend using table.find
e.g.

if table.find({"Persianta", "Titaniturn"}, player:WaitForChild("Body").Value) then

That is very helpful, I actually didn’t know that you could use table.find in that way!

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