Unable To Cast Array To RaycastParams

Hi, I’m trying to make a system where you can build in the game, after figuring out that FindPartOnRay() is depreciated I moved to raycasts, though when I try to build in game I get the following error:

Unable to cast array to Raycast params

This is the script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PlaceStructure = ReplicatedStorage:WaitForChild("PlaceStructure")
local MaterialFolder = ReplicatedStorage:WaitForChild("Materials")

local UIS = game:GetService("UserInputService")
local RunService = game:GetService("RunService")

local player = game.Players.LocalPlayer
local StructureFrame = script.Parent.StructureFrame
local Character = player.Character or player.Character:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")

local Mouse = player:GetMouse()

local yAxisBuildingOffset = 5
local MaxPlaceDistance = 50
local RotateKeyIsPressed = false
local PlacingStructureDebounce = false

for _, structureButton in pairs(StructureFrame:GetChildren()) do
	if structureButton:IsA("TextButton") then
		structureButton.MouseButton1Down:Connect(function()
			
			StructureFrame.Visible = false
			
			local yOrientation = 0
			local InRangeToPlace = false
			local placedStructure
			
			if PlacingStructureDebounce == false then
				PlacingStructureDebounce = true
				
				local ClientStructure = MaterialFolder:FindFirstChild(structureButton.Name):Clone()
				ClientStructure.BrickColor = BrickColor.new("Forest green")
				ClientStructure.Material = "Neon"
				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, Character}
					local hit, Position = game.Workspace:Raycast(MouseRay.Origin, MouseRay.Direction * 1000, IgnoreList)
					
					if hit and (hit:IsA("Terrain") or hit.Name:lower() == "terrain") and (HumanoidRootPart.Position - ClientStructure.Position).Magnitude < MaxPlaceDistance then
						InRangeToPlace = true
						ClientStructure.BrickColor = BrickColor.new("Forest green")
					else
						InRangeToPlace = false
						ClientStructure.BrickColor = BrickColor.new("Crimson")	
					end
					
					local newAnglesCFrame = CFrame.Angles(0, math.rad(yOrientation), 0)
					local NewCFrame = CFrame.new(Position.X, Position.Y + yAxisBuildingOffset, Position.Z)
					ClientStructure.CFrame = NewCFrame * NewCFrame
				end)
				
				UIS.InputBegan:Connect(function(input)
					if input.KeyCode == Enum.KeyCode.R then
						RotateKeyIsPressed = true
						
						local RotationSpeed = 3
						
						while RotateKeyIsPressed do
							wait()
							if PlacingStructureDebounce == true then
								yOrientation = yOrientation + RotationSpeed
							end
						end
					end
				end)
				
				UIS.InputEnded:Connect(function(input)
					if input.KeyCode == Enum.KeyCode.R then
						RotateKeyIsPressed = false
					end
				end)
				
				UIS.InputBegan:Connect(function(input)
					if input.UserInputType == Enum.UserInputType.MouseButton1 then
						if PlacingStructureDebounce == true then
							if InRangeToPlace == true then
								local StructureCFrame = ClientStructure.CFrame
								placedStructure = PlaceStructure:InvokeServer(ClientStructure.Name, StructureCFrame)
								
								if placedStructure == true then
									PlacingStructureDebounce = false
									ClientStructure:Destroy()
									StructureFrame.Visible = true
								end
							end
						end
					end
				end)
			end
		end)
	end
end

Thanks In Advance

Did you forget to put this in a RaycastParams?
Try this:

local Params = RaycastParams.new()
Params.FilterDescendantsInstances = {ClientStructure, Character}
Params.FilterType = Enum.RaycastFilterType.Blacklist

local hit, Position = game.Workspace:Raycast(MouseRay.Origin, MouseRay.Direction * 1000, Params)
1 Like

Please read the documentation. You need to create a RaycastParams object.

					local IgnoreList = {ClientStructure, Character}
                    local raycastParams = RaycastParams.new()
                    raycastParams.FilterDescendantInstances = IgnoreList
                    raycastParmams.FilterType = Enum.RaycastFilterType.Blacklist
					local hit, Position = game.Workspace:Raycast(MouseRay.Origin, MouseRay.Direction * 1000, raycastParams)

Interestingly enough I actually thought that was the solution, though I get 2 more errors when I try to place this now

IsA is not a valid member of RaycastResult -Line 52

Players.Itz_Visually.PlayerGui.BuildingGui.Builder:61: attempt to index nil with X -Line 61

Do I need a RaycastResult? I thought that was just for debugging.

Also in case any way this comes in handy, I also have the script which allows the server to see the placed part

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PlaceStructure = ReplicatedStorage:WaitForChild("PlaceStructure")
local MaterialFolder = ReplicatedStorage:WaitForChild("Materials")

PlaceStructure.OnServerInvoke = function(player, StructureName, StructureCFrame)
	local Crafted
	local RealStructure = MaterialFolder:FindFirstChild(StructureName):Clone()
	
	if RealStructure then
		RealStructure.CFrame = StructureCFrame
		RealStructure.Parent = game.Workspace
		Crafted = true
	else
		Crafted = false
	end
	
	return Crafted
end

For the first error, Raycasts return tables, not instances. You cant use ‘IsA’ on a table.
To get the instance from the Raycast; You simply need to do raycastResult.Instance.

local result = workspace:Raycast(MouseRay.Origin, MouseRay.Direction * 1000, IgnoreList)
if result then
    local object = result.Instance -- this is the instance
end

for the second error, i dont really know what it means since i dont know what part of the script its coming from.