"Unable to cast Array to bool" on Raycast

Right now, when I tried to script and test a gun, the accessory got in the way and the bullet didn’t hit, so I fixed the script.

local ignore = {}

function Raycasting(plr,WhatGun,MousePos)
	local FirstMouse = MousePos
	print(MousePos)
	local raycast = Ray.new(WhatGun.BulletGoes.Position, (MousePos-WhatGun.BulletGoes.Position).unit*100)
	local Paet, Position = game.Workspace:FindPartOnRayWithIgnoreList(raycast , plr.Character , ignore , false , true , true)
	if Paet then
		if Paet.Parent:IsA("Accessory") then
			table.insert(ignore,Paet) -- adds to the ignore list
			return Raycasting(plr,WhatGun,MousePos)-- do the raycast again
		end
		local humanoid = Paet.Parent:FindFirstChild("Humanoid")
		if humanoid then
			if humanoid.Health > 0 then
				if Paet.Name == "Head" then
					humanoid:TakeDamage(50)
					local HitFlesh = game.ServerStorage.Damaged.hitflesh:Clone()
					game:GetService("Debris"):AddItem(HitFlesh, 0.4)
					HitFlesh.Parent = Paet
					HitFlesh:Play()
					if humanoid.Health < 1 then
						local velocity = Instance.new("BodyVelocity")
						game:GetService("Debris"):AddItem(velocity, 0.1)
						velocity.Name = "BulletHoel"
						velocity.Parent = Paet
						velocity.Velocity = (Paet.Position - Position) * 10
						local HitFlesh = game.ServerStorage.DeathByBullet.hitflesh:Clone()
						game:GetService("Debris"):AddItem(HitFlesh, 1)
						HitFlesh.Parent = Paet
						HitFlesh:Play()
						local deathanim = humanoid.Parent:FindFirstChild("DeathAnim")
						if deathanim then
							humanoid.Parent:BreakJoints()	
						end	
					end
				else
					local HitFlesh = game.ServerStorage.Damaged.hitflesh:Clone()
					game:GetService("Debris"):AddItem(HitFlesh, 0.4)
					HitFlesh.Parent = Paet
					HitFlesh:Play()
					humanoid:TakeDamage(10)
					if humanoid.Health < 1 then
						local velocity = Instance.new("BodyVelocity")
						game:GetService("Debris"):AddItem(velocity, 0.1)
						velocity.Name = "BulletHoel"
						velocity.Parent = Paet
						velocity.Velocity = (Paet.Position - Position) * 10
					end
				end
			elseif humanoid.Health < 1 then
				local velocity = Instance.new("BodyVelocity")
				game:GetService("Debris"):AddItem(velocity, 0.1)
				velocity.Name = "BulletHoel"
				velocity.Parent = Paet
				velocity.Velocity = (Paet.Position - Position) * 10
				local HitFlesh = game.ServerStorage.Damaged.hitflesh:Clone()
				game:GetService("Debris"):AddItem(HitFlesh, 0.4)
				HitFlesh.Parent = Paet
				HitFlesh:Play()
			end
			local Blud = game.ServerStorage.Blood_notxbox.ParticleEmitter:Clone()
			game:GetService("Debris"):AddItem(Blud, 4)
			Blud.Parent = Paet
			Blud.Script.Disabled = false
		end
	end
	local randomcounter = math.random(1,2)
	if randomcounter == 1 then
		local muzzle = game.ServerStorage.OneMuzzle:Clone()
		local welder = Instance.new("Weld")
		welder.Parent = muzzle
		welder.Part1 = WhatGun.BulletGoes
		welder.Part0 = muzzle
		game:GetService("Debris"):AddItem(muzzle, 0.125)
		muzzle.Parent = game.Workspace
		muzzle.Position = WhatGun.BulletGoes.Position
	elseif randomcounter == 2 then
		local muzzle = game.ServerStorage.TwoMuzzle:Clone()
		local welder = Instance.new("Weld")
		welder.Parent = muzzle
		welder.Part1 = WhatGun.BulletGoes
		welder.Part0 = muzzle
		game:GetService("Debris"):AddItem(muzzle, 0.125)
		muzzle.Parent = game.Workspace
		muzzle.Position = WhatGun.BulletGoes.Position
	end
	local Replicated = game.ServerStorage.ShootBlock:Clone()
	local welder = Instance.new("Weld")
	welder.Parent = Replicated
	welder.Part1 = WhatGun.BulletGoes
	welder.Part0 = Replicated
	game:GetService("Debris"):AddItem(Replicated, 1)
	Replicated.Parent = game.Workspace
	Replicated.Position = WhatGun.BulletGoes.Position
	Replicated.CSAKSHOOT:Play()
	local bulletway = Instance.new("Part")
	bulletway.BrickColor = BrickColor.new("New Yeller")
	bulletway.Parent = game.Workspace
	bulletway.CanCollide = false
	bulletway.Anchored = true
	bulletway.CastShadow = false
	bulletway.Material = Enum.Material.Neon
	local distance = (MousePos-WhatGun.BulletGoes.Position).magnitude
	bulletway.CFrame = CFrame.new(WhatGun.BulletGoes.Position,Position)*CFrame.new(0,0,-distance/2)
	bulletway.Size = Vector3.new(0.1,0.1,distance)
	game:GetService("Debris"):AddItem(bulletway, 0.08)
end

script.Parent.Reload.OnServerEvent:Connect(function(plr)
	script.Parent.Handle.AK47_Reload:Play()
	wait(2.1)
	script.Parent.Handle.AK47_Reload:Stop()
end)

script.Parent.ShootRemote.OnServerEvent:Connect(function(plr,WhatGun,MousePos)
	Raycasting(plr,WhatGun,MousePos)
end)

However, with this script, the 7th and 117th columns are displayed as “Unable to cast Array to bool” and do not work. What should I do?
Thank you.

The parameters for FindPartOnRayWithIgnoreList are listed here:

On line seven, you have the player’s character as the second parameter when it should be the ignore table:
local Part, Position = game.Workspace:FindPartOnRayWithIgnoreList(raycast , ignore)

If you want to ignore the player insert it into ignore:
table.insert(plr.Character, ignore)

Also, there’s only two true/false values after that so determine what you want to put there based on the screenshot above.

3 Likes