Unable to cast double to Vector3

I get the error Unable to cast double to Vector3 in line 6:

function dig(controller)
	local rayResult = workspace:Raycast(rayController.Position, rayController.CFrame.LookVector * 20, rayParams)
	print(rayResult.Position)
	
	if rayResult then
		game.Workspace.Terrain:FillBlock(CFrame.new(Vector3.new(rayResult.Position.X, rayResult.Position.Y, rayResult.Position.Z)), 6, Enum.Material.Air)
		print("Filled")
	end
end

I have no idea how to fix it, even after looking trough many posts on the devforum.

why did you put Vector3.new in CFrame.new
if i remember correctly CFrame.new convert normal vector3 value (and number) into CFrame so you dont need to put Vector3.new in CFrame.new

image

Without the Vector3.new() and by using CFrame.new(rayResult.Position) I get the same error too.

for size you need to use Vector3.new

This is the parameters of :FillBlock()
Terrain:FillBlock(CFrame,Vector3,Material)
This is the parameters that you put in:
Terrain:FillBlock(CFrame,double,Material)

I think this is more inline with what you are looking for:

game.Workspace.Terrain:FillBlock(CFrame.new(Vector3.new(rayResult.Position.X, rayResult.Position.Y, rayResult.Position.Z)), Vector3.new(6,6,6), Enum.Material.Air)

what is the difference between CFrame.new(Vector3.new(Number here)) and CFrame.new(Number here)

pretty sure it just takes it as a position value, there isn’t really a difference at all, I just didn’t change it because it’s not relevant to the issue

also i think you can replace the “rayResult.Position.X, rayResult.Position.Y, rayResult.Position.Z” with “rayResult.Position” unless it doesnt work

Here, simplified:
game.Workspace.Terrain:FillBlock(CFrame.new(rayResult.Position), Vector3.new(6,6,6), Enum.Material.Air)

It’s confusing that a double gets accepted when :FillBall is used like this:


but in the script it doesn’t.
Anyways thank you, that fixed it.

what is the difference between CFrame.new(Vector3.new(Number here)) and CFrame.new(Number here)

I changed it to

game.Workspace.Terrain:FillBall(rayResult.Position, 6, Enum.Material.Air)

Thanks for pointing it out @gamingvn132

that’s because it’s a radius, spheres generally only need a radius/diameter and a position to be made, however when you use FillBlock it could be a “Rectangular Prism” not just a “Cube” which means it requires a height, length, and width.