Attempt to index function with "FilterDescendantsInstances"

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want this raycast localscript to work properly.

  2. What is the issue? Include screenshots / videos if possible!
    Whenever I run this script it just gives me the error shown as the title.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I used roblox’s tutorial on raycasting to help but it did not work. I looked on the Developer Hub though that also did not work. I don’t really know what the problem is. The only thing I can think of is that I am using a localscript and not a server script but I do not know how that would change much.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local pistol = script.Parent
local rayOrigin = pistol:WaitForChild("Handle").Position
local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local rayDirection = mouse.Hit.LookVector*100

local function firelaser()
	local raycastParams = RaycastParams.new
	raycastParams.FilterDescendantsInstances = {player, script.Parent.Handle}
	raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
	local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
	if raycastResult then
		print("Object detected")
	end
end

pistol.Activated:Connect(function()
	firelaser()
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

You forgot the parenthesis at the end of RaycastParams.new. It should be RaycastParams.new()

1 Like

Tysm. Typos can really mess us up lol.