-- if Target.Parent ~= PlayerCharacter and Target.Parent:FindFirstChildOfClass("Humanoid") and not table.find(AlreadyHit, Target.Parent) and Target.Parent:FindFirstChildOfClass("Humanoid"):GetAttribute("IsParrying") ~= true and Target.Parent:FindFirstChildOfClass("Humanoid"):GetAttribute("Block") == false then
As we can see here, this if statement has a bunch of conditions. I was wondering if there’s a way to put all of the conditions into a table or just condense them into something smaller.
To make the if statement easier to read, you can scretch it to multiple lines, just like that:
if Target.Parent ~= PlayerCharacter and Target.Parent:FindFirstChildOfClass("Humanoid")
and not table.find(AlreadyHit, Target.Parent) and Target.Parent:FindFirstChildOfClass("Humanoid"):GetAttribute("IsParrying") ~= true
and Target.Parent:FindFirstChildOfClass("Humanoid"):GetAttribute("Block") == false then
-- Do something
end
Edit: I have just realized that this is not something what you might want.
-- if Target.Parent ~= PlayerCharacter and Target.Parent:FindFirstChildOfClass("Humanoid") and not table.find(AlreadyHit, Target.Parent) and Target.Parent:FindFirstChildOfClass("Humanoid"):GetAttribute("IsParrying") ~= true and Target.Parent:FindFirstChildOfClass("Humanoid"):GetAttribute("Block") == false then
Can be:
local parent = Target.Parent
local Human = parent:FindFirstChildOfClass("Humanoid")
if parent ~= PlayerCharacter and Human and not table.find(AlreadyHit,parent) then
if not Human:GetAttribute("IsParrying") and not Human:GetAttribute("Block") then
-- do more stuff
end
end
function condition(Target, PlayerCharacter, AlreadyHit): boolean
return Target.Parent ~= PlayerCharacter and Target.Parent:FindFirstChildOfClass("Humanoid") and not table.find(AlreadyHit, Target.Parent) and Target.Parent:FindFirstChildOfClass("Humanoid"):GetAttribute("IsParrying") ~= true and not Target.Parent:FindFirstChildOfClass("Humanoid"):GetAttribute("Block") and true or false
end
if condition(Target, PlayerCharacter, AlreadyHit) then
-- stuff here
end
Also don’t lengthify the return I suggest you to use @JustOneFreshAccount’s solution.
function condition(...): boolean
if not ... then
return false
end
-- ...
return true
end