Unable to Cast array to Bool

Good afternoon, I am trying to make a simple placement system and ran into an error I’ve never seen before.

local worlds = {
	["world1"] = workspace.Map.Spawns.world1:GetChildren(),
	["World2"] = workspace.Map.Spawns.world2:GetChildren(),
	["world3"] = workspace.Map.Spawns.world3:GetChildren(),
	["world4"] = workspace.Map.Spawns.world4:GetChildren(),
	["world5"] = workspace.Map.Spawns.world5:GetChildren(),
	["world6"] = workspace.Map.Spawns.world6:GetChildren(),
	["world7"] = workspace.Map.Spawns.world7:GetChildren()
}

local randomtable = {}
for i, v in pairs(worlds) do
	for i2, v2 in pairs(v) do
		table.insert(randomtable, v2)
	end
end


local replicatedstorage = game.ReplicatedStorage
local PFunction = game.ReplicatedStorage:WaitForChild("PFunction")
local structures = game.ReplicatedStorage:WaitForChild("Structures")
local userinputservice = game:GetService("UserInputService")

local runservice = game:GetService("RunService")
local player = game.Players.LocalPlayer
local structureFrame = script.Parent.Frame
local char = player.Character or player.Character:Wait()
local humanoidrootpart = char:WaitForChild("HumanoidRootPart")

local mouse = player:GetMouse()


local yBuildingOffset = 5
local rKeyispressed = false
local placingstructure = false

for i, v in pairs(structureFrame:GetChildren()) do
	if v:IsA("TextButton") then
		v.MouseButton1Up:Connect(function()
			structureFrame.Visible = false
			local goodtoplace = false
            local placedstructure
			local yOrientation = 0
			
			if placingstructure == false then
				placingstructure = true
				
				local clientstructure = structures:FindFirstChild(v.Name):Clone()
				clientstructure.CanCollide = false
				clientstructure.Parent = game.Workspace	
                
				local StartingCframe = CFrame.new(0, -2, -15)
				clientstructure.CFrame = humanoidrootpart.CFrame:ToWorldSpace(StartingCframe)

				runservice.RenderStepped:Connect(function()
					local mouseray = mouse.UnitRay
					local castray = Ray.new(mouseray.Origin, mouseray.Direction * 1000)
					local ignorelist = {clientstructure, char, randomtable}
					print(ignorelist)
					local hit, position = workspace:FindPartOnRayWithIgnoreList(castray, ignorelist, randomtable)
                    
					if hit and hit.Shape == Enum.PartType.Block then
					
						goodtoplace = true
					else
						goodtoplace = false
					end


					local NewAngleCframe = CFrame.Angles(0, math.rad(yOrientation), 0)
					local NewCframe = CFrame.new(position.X, position.Y + yBuildingOffset, position.Z)
					clientstructure.CFrame = NewCframe * NewAngleCframe
				end)
				userinputservice.InputBegan:Connect(function(input)
					if input.KeyCode == Enum.KeyCode.R  then
						rKeyispressed = true

						local rotationspeed = 5
						while rKeyispressed do
							task.wait()
							if placingstructure == true then
								yOrientation = yOrientation	+ rotationspeed
							end
						end
					end
				end)
				userinputservice.InputEnded:Connect(function(input)
					if input.KeyCode == Enum.KeyCode.R  then
						rKeyispressed = false
					end
				end)
				userinputservice.InputBegan:Connect(function(input)
					if input.UserInputType == Enum.UserInputType.MouseButton1 then
						if placingstructure == true  then
							if goodtoplace == true then
								local StructureCframe = clientstructure.CFrame
								placedstructure = PFunction:InvokeServer(clientstructure.Name, StructureCframe)

								if placedstructure == true then
									placingstructure = false 
									clientstructure:Destroy()
									structureFrame.Visible = true
								end
							end
						end
					end
				end)
			end
		end)
	end
end

local ignorelist = {clientstructure, char, randomtable}
					local hit, position = workspace:FindPartOnRayWithIgnoreList(castray, ignorelist, randomtable)
                    

This is the error part

I’m 90% sure the third parameter to FindPartOnRayWithIgnoreList should be a Boolean.

Even then, workspace:FindPartOnRayWithIgnoreList() is deprecated and should not be used. You can use workspace:Raycast() with a RaycastParams object instead.

I removed randomtable from the parameter because I realized it was already part of ignore list.
New error : Unable to cast value on Object

You can use workspace:Raycast() with a RaycastParams object instead.

Solution

How would you go about doing that?

Its asking you to have parameters for the raycast.

  -- create raycast params to configure the raycasting settings
                local raycastParams = RaycastParams.new()
                raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
                raycastParams.FilterDescendantsInstances = {clientstructure, char}

                -- since ur using renderstep to update u can do this as you check 
                runservice.RenderStepped:Connect(function()
                    local mousePos = mouse.Hit.Position
                    local rayOrigin = humanoidrootpart.Position
                    local rayDirection = (mousePos - rayOrigin).Unit * 1000
                    raycastParams.FilterDescendantsInstances = {clientstructure, char, unpack(randomtable)}

                    -- Use workspace:Raycast with the RaycastParams object
                    local rayResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)

                    if rayResult and rayResult.Instance and rayResult.Instance.Shape == Enum.PartType.Block then
                        goodtoplace = true
                    else
                        goodtoplace = false
                    end

                    local NewAngleCframe = CFrame.Angles(0, math.rad(yOrientation), 0)
                    local NewCframe = CFrame.new(mousePos.X, mousePos.Y + yBuildingOffset, mousePos.Z)
                    clientstructure.CFrame = NewCframe * NewAngleCframe
                end)

Let me know if it works

Thanks for the explanation.
It works for the most part. It just won’t let me place it now and I gotta figure out why.

Try to debug your code like printing, to check. And also make it that before running the render-step make sure the model you’re placing is already placed.