Unable to cast value to object (IsA error)

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 am attempting to detect a player’s accessories and add them to the raycast whitelist so the ray will go through it.

  1. What is the issue? Include screenshots / videos if possible!

I get the error in the png below and I’m not exactly use what it means.

Here’s my full code for anyone who needs it

local tool = script.Parent
local shoot_part = tool.Shoot
local remote = tool.OnShoot
local bulletamt = script.Parent.Bulletval
local raycastParams = RaycastParams.new()


local getbv = script.Parent.Bulletval
bulletamt.Value = 12
local remoteI = tool.Onreload

local Workspace = game:GetService("Workspace")

getbv.Changed:Connect(function(Change)
	print("Change:", Change)
	
end)

remote.OnServerEvent:Connect(function(player, position)
	if bulletamt.Value >= 1 then
		script.Parent.GunShot:Play()
		
		raycastParams.FilterType = Enum.RaycastFilterType.Whitelist
		raycastParams.FilterDescendantsInstances = {player:IsA("Accessory")}
		raycastParams.IgnoreWater = true

		print(raycastParams.FilterDescendantsInstances)
		print(raycastParams.IgnoreWater)
		print(raycastParams.FilterType)
	
		local origin = shoot_part.Position
		local direction = (position - origin).Unit
		local result = Workspace:Raycast(shoot_part.Position, direction*300, raycastParams)

		local intersection = result and result.Position or origin + direction*300
		local distance = (origin - intersection).Magnitude

		local bullet_clone = game.ServerStorage.Bullet:Clone()
		bullet_clone.Size = Vector3.new(0.1, 0.1, distance)
		bullet_clone.CFrame = CFrame.new(origin, intersection)*CFrame.new(0, 0, -distance/2)
		bullet_clone.Parent = Workspace
		bullet_clone.Transparency = 0.5
		
		if result  then
			print(result)
			local part = result.Instance
			print(part)
			local humanoid = part.Parent:FindFirstChild("Humanoid") or part.Parent.Parent:FindFirstChild("Humanoid")
			if humanoid then
				if part.Name == "LeftFoot" or part.Name == "RightFoot" or part.Name == "LeftHand" or part.Name == "RightHand" then
					humanoid:TakeDamage(1)
					print("1")
				elseif part.Name == "Head" then
					humanoid:TakeDamage(50)
					print("50")
				elseif part.Name == "UpperTorso" or part.Name == "LowerTorso" or part.Name == "HumanoidRootPart" then
					humanoid:TakeDamage(20)
					print("20")
				elseif part.Name == "LeftLowerArm" or part.Name == "RightLowerArm" or part.Name == "LeftUpperArm" or part.Name == "RightUpperArm" or part.Name == "Left Arm" or part.Name == "Right Arm" or part.Name == "Right Leg" or part.Name == "Left Leg" then
					humanoid:TakeDamage(10)
				else
					humanoid:TakeDamage(5)
					print("10")


				end

			end
			
			
		end
		
		print(script.Parent.Bulletval.Value)
		script.Parent.Bulletval.Value = script.Parent.Bulletval.Value - 1
		print(script.Parent.Bulletval.Value)
		--bullet stuff
		local b = " bullets"
		local amt = bulletamt.Value
		script.Parent.GunInterface.Frame.TextLabel.Text = amt .. b
		
		wait(0.25)
		bullet_clone:Destroy()
	-- empty bullet click sound
	elseif getbv.Value == 0 then
		print("No more bullets")
		script.Parent.Click:Play()
	end
		
end)
	

-- reloading
remoteI.OnServerEvent:Connect(function(player, client)

	if script.Parent.Bulletval.Value == 0 then
		script.Parent.Bulletval.Value = 12
		print("Reloaded")
		local b = "bullets"
		print(player)
		script.Parent.Gunreload:Play()
		player.PlayerGui.GunInterface.Frame.TextLabel.Text = script.Parent.Bulletval.Value .. b
		
	end

end)
  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I’ve looked around but there wasn’t any post that had this issue with a “IsA” function (?)

“player” in this case, is a player object and there’s part of your issue.

1 Like

Instance:IsA() returns a bool, not an object. RaycastParams.FilterDescendantsInstances is an array of objects.

2 Likes

ok so I tried this and still got the error, but thank you!

What would you suggest for this? Should I check if it has accessories then get the names of them, then run it through the whitelist? I feel like that may be more code then needed.

Yeahhhhh tried that but no luck.

Here’s the adapted code which continously prints “do”


		local descendants = player:GetDescendants()

		
		for index, descendant in pairs(descendants) do
		print("do")
			if descendant:IsA("Accessory") then
				print("Its acessory")
				print(descendant.Name)
			end
		end

EDIT
Here’s my revised script which successfully finds and names accesories. I will be using this to expand my code.

local descendants = player.Character:GetDescendants()

		
		for index, descendant in pairs(descendants) do
		print("do")
			if descendant:IsA("Accessory") then
				print("Its acessory")
				print(descendant.Name)
			end
		end