If statement running despite condition being false

print(v:FindFirstAncestorWhichIsA("Model"):FindFirstChildWhichIsA("Humanoid") or v:FindFirstAncestorWhichIsA("Model"):FindFirstAncestorWhichIsA("Model") and not  players:GetPlayerFromCharacter(v:FindFirstAncestorWhichIsA("Model")) == players:GetPlayerFromCharacter(script.Parent.Parent.Parent))

This returns humanoid for some reason instead of returning true or false, how could I change that

You can throw a ~= nil on the end of it all. In Lua, anything that is not nil and not false is the same as true in conditionals though, so im not sure why it matters to you.

That’s so much logic on a single line it’s hard to even see what’s going on. Broken down we have 3 conditions here.

print(
    v:FindFirstAncestorWhichIsA("Model"):FindFirstChildWhichIsA("Humanoid") or                     
    v:FindFirstAncestorWhichIsA("Model"):FindFirstAncestorWhichIsA("Model") and not  
    players:GetPlayerFromCharacter(v:FindFirstAncestorWhichIsA("Model")) == players:GetPlayerFromCharacter(script.Parent.Parent.Parent)
)

we can extract those out to 4 variables to clean them up more

local humanoid = v:FindFirstAncestorWhichIsA("Model"):FindFirstChildWhichIsA("Humanoid")
local model = v:FindFirstAncestorWhichIsA("Model"):FindFirstAncestorWhichIsA("Model")

local ancestorPlayer = players:GetPlayerFromCharacter(v:FindFirstAncestorWhichIsA("Model"))
local parentPlayer = players:GetPlayerFromCharacter(script.Parent.Parent.Parent)

print(humanoid or model and not ancestorPlayer == parentPlayer)

so if either humanoid or model are nil, then it will check if not ancestorPlayer == parentPlayer

if humanoid or model aren’t nil; it will just print them. humanoid was evaluated first, it wasn’t nil, thus it’s printing humanoid.

1 Like

My problem is that it just regards the latter part of the statement so long as there is a humanoid. returning true if there is a humanoid regardless if its the player that triggered the script.

(a or b) and c
And is evaluated first, so put the others in parentheses.

It still prints out humanoid. :shallow_pan_of_food: