Raycasting, "Attempt to call a table value"?

Good morning guys, i have this error, that is very very weird, just for the fact that i have did this before and this didnt even give me this error while raycasting other guns that i have coded. I have thought that the problem may be my “BodyAttach” part, that is just a part that cointains motor6ds and sounds for the gun, but when i dont put anything on the FilterDescendantsInstances() brackets, the error stills appearing. Here i leave my code, also this is a LocalScript

local WeaponTool = script.Parent.MP40

local function shoot()
    local now = tick()
    if now - lastFire >= shootDelay then
			lastFire = now
			
			
			local origin = WeaponTool.ShootPart.Position
			local destination = mouse.Hit.Position
			local direction = (destination - origin).Unit*700
			local raycastParams = RaycastParams.new()
			raycastParams.FilterDescendantsInstances(WeaponTool)
			raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
			local result = workspace:Raycast(origin, direction, raycastParams)
			local intersection = result and result.Position or origin + direction
			local distance = (origin - intersection).Magnitude
			onShootEvent:FireServer(distance, result, intersection, origin, lastFire, shootDelay)
		
			SoundEvent.OnClientEvent:Connect(function(plr, shootsound)
					shootsound:Play()
			end)
		
		
			Bullets.Value -= 1
			
		local shootAnimation = Instance.new("Animation")
		shootAnimation.AnimationId = "rbxassetid://5671559974"
		local shootAnimTrack = char:WaitForChild("Humanoid"):LoadAnimation(shootAnimation):Play()
		
		
    else
        --Let use know they have to wait, if you want too
    end
end

Output:


Workspace
workspace tool

Thanks in advance!!!

FilterDescendantsInstances is a property that takes an array as it’s value, not a function. So you need to something like this:
raycastParams.FilterDescendantsInstances = {WeaponTool}

2 Likes

Ah yes, you are trying to call a table value that must not exist. That happens to me sometimes. Is there a value that does nothing you are trying to call?

1 Like

Tell me what Line 62 is in your code please.

1 Like

Pretty sure he is talking about the line with raycastParams.FilterDescendantsInstances(WeaponTool)

1 Like

Lemme look at the code real fast.

1 Like

Ben’s line is correct, to call a table value for your code you use this:
raycastParams.FilterDescendantsInstances = {WeaponTool} You are setting it equal to the value.
Using this line under here will not work because you are not calling the table right.
raycastParams.FilterDescendantsInstances(WeaponTool) – This line is not right. Replace it with the one above here.

2 Likes

In under to call a table, you need to set it equal to the table.

1 Like

Thanks BenMactavsin and jumbopushpop112!!! It was something very simple and basic, sorry!!! Thanks so much!!

No problem man! It’s ok. We all make mistakes on basic code. Trust me I have before. Mark one of the posts with the solution so that this topic is flagged as completed.