Unable to cast value to Objects

I want to make a laser that destroys the parts it hits, by negating them, but i get a error.

This is the script:
image

This is the error:
image

Can somebody help?

1 Like

I’m guessing it’s because they expect a list of objects to Subtract/Union. So a simple fix would be to encase h in the SubtractAsync and UnionAsync with curly brackets, so {h}

Alright, i’ll try that out, thanks in advance.

I still have the same error, and the parts aren’t negating.

May I see the change you’ve done to your script? I would also recommend sending it as a codeblock via 3 backticks(```) at the start and end of your code block to allow me to easily edit it for you if needed!

Alright, here it is:

script.Parent.Touched:Connect(function(h)
	if h:IsA("Part") then
		script.Parent:SubtractAsync(h)
		script.Parent:UnionAsync({h})
	end
end)

You need to also do it for SubtractAsync

script.Parent.Touched:Connect(function(h)
	if h:IsA("Part") then
		script.Parent:SubtractAsync({h})
		script.Parent:UnionAsync({h})
	end
end)
2 Likes

Now, no errors are popping up in console, but the part isnt negating.

Wait from what I can tell after reading through your post again, can’t you just use Destroy()?

script.Parent.Touched:Connect(function(h)
	if h:IsA("Part") then
		h:Destroy()
	end
end)
1 Like

Not really, since i want to make it create a hole, and not destroy the part fully.

Oh, i realize what i did wrong now.

image
I have to set the parent to workspace.

4 Likes