":IsA("Model")" is picking up tools rather than models while looking for a sword

Hey! I’m making a sword and whenever the player does a successful parry the enemies attack gets blocked and they play an animation. However, when trying to find the model that has the effect in it (The sword model. It’s separate from the tool “Arming Sword”), the output keeps printing that it’s found the tool “Arming Sword” despite being told to ONLY look for models.

Here’s some pictures for a better understanding:
image


No Parry effect (Flash):

What the hierarchy looks like:
image

Here’s the entire code block

	-- Enemy Attack Logic
	local function attack(target)
		local function checkDistance()
			local enemyRootPart = Enemy:FindFirstChild("HumanoidRootPart")
			local targetRootPart = target:FindFirstChild("HumanoidRootPart")

			if not enemyRootPart or not targetRootPart then
				return math.huge -- Return large distance if part is missing
			end

			return (enemyRootPart.Position - targetRootPart.Position).Magnitude
		end

		local distance = checkDistance()

		if distance > Attackrange then -- Move towards target if out of range
			local targetRootPart = target:FindFirstChild("HumanoidRootPart")
			if targetRootPart then
				humanoid:MoveTo(targetRootPart.Position)
			end
		elseif distance <= Attackrange then -- Attack when in range
			wait(0.3)
			if target.Humanoid and target.Humanoid.Health > 0 then	
				coroutine.wrap(PlayAttackAnimation)()
			end

			local function AttackWait()
				while AttackTrack and AttackTrack.IsPlaying do
					rotateToFace(target) -- Continue facing target
					wait()
				end
			end
			
			coroutine.wrap(AttackWait)()
			

			distance = checkDistance() -- Re-check distance
			if distance <= MaxAttackrange.Value then
				if target.Humanoid and target.Humanoid.Health > 0 then
					
					local BlockedAttack = false
					
				
					
					local function CheckIfParry()
						for _, child in pairs(target:GetChildren()) do
							if child:IsA("Tool") then
								print("Found tool on", target.Name)

								local Parry = child:FindFirstChild("Parry")

								if not Parry then
									return
								end

								print("Found Parry")
								
								wait(AnimationLength)

								if Parry.Value == false then
									return
								end

								BlockedAttack = true
								
								print("Making BlockedAttack true")

							end
						end
					end
					
					CheckIfParry()
					
					local function CheckForSword()
						for _, child in pairs(target:GetChildren()) do
							if child:IsA("Model") then
								print("Found Model", child.Name)
								
								local Blade = child:FindFirstChild("Blade")
								
								if not Blade then
									return
								end
								print("Found blade")
								
								local Flash = Blade:FindFirstChild("Flash")
								
								if not Flash then
									return
								end
								print("FoundFlash")
								
								Flash.Enabled = true
								
								wait(1)
								
								Flash.Enabled = false
								
							end
						end
					end
					
					wait()

					if BlockedAttack == false then
						distance = checkDistance()
						if distance > MaxAttackrange.Value then
							return
						end
						
						while AttackTrack and AttackTrack.IsPlaying do
							wait()
						end
						
						target.Humanoid:TakeDamage(DamageAmount) -- Inflict damage
						
					elseif BlockedAttack == true then
						coroutine.wrap(CheckForSword)()
						PlayBlockedAnimation()
					end
					

				end
				wait(AttackCooldown) -- Wait for cooldown
			end
		end 
	end
2 Likes

Tool “inherits” from Model:

, allowing you to use stuff like :PivotTo on them. You should use .ClassName to ignore inheritance, i.e. child.ClassName == "Model".

2 Likes

Thank you bro, I was tweaking out thinking it was some sort of programming bug.

2 Likes

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