CFrame nil Mining System Help

Basicly if you mine a block where there is sky it just breaks.


function BoxDetermination(Target, distance)

	if distance <= 20 then
		BoxSelection.Adornee = Target
		BoxSelection.Color3 = Color3.fromRGB(100, 255, 16)
		OreFrame.Visible = true
		CanMine = true
		local Targeted = tostring(Target)
		
		--Changing Information
		
		OreFrame.Ore.Text = tostring(Target).." - "..tostring(Target.Ore.Value)
		OreFrame.Ore.TextColor3 = OreModule[Targeted]["OreColor"]
		OreFrame.Front.Bar.BackgroundColor3 = OreModule[Targeted]["OreColor"]
		OreFrame.Front.Bar1.BackgroundColor3 = OreModule[Targeted]["DarkOreColor"]
		OreFrame.CoinValue.Text = "Coin Value: "..tostring(OreModule[Targeted]["CoinValue"])
	else
		BoxSelection.Adornee = Target
		BoxSelection.Color3 = Color3.fromRGB(255, 42, 42)
		OreFrame.Visible = true
		CanMine = false
		
		--Changing Information
		OreFrame.Ore.Text = "Far from range"
		OreFrame.Ore.TextColor3 = Color3.fromRGB(255, 42, 42)
		OreFrame.Front.Bar.BackgroundColor3 = Color3.fromRGB(255, 42, 42)
		OreFrame.Front.Bar1.BackgroundColor3 = Color3.fromRGB(166, 27, 27)
		OreFrame.CoinValue.Text = ""
	end
end
function RepeatMine(Target)
	local Bar = OreFrame.Front.Bar
	
	
	while wait() do
		if Target == nil then
			print("BRaey")
		end
		Bar:TweenSize(UDim2.new(0.948, 0, 0.735, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, Time, false)
		if CanMine == false or hold == false or Mining == false or TheChange == false then
			Bar:TweenSize(UDim2.new(0.027, 0, 0.735, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.01, true)
				break
			else
			
			
			if Bar.Size.X.Scale > 0.9 then
				
				RemoteEvent:FireServer(BoxSelection.Adornee)
				
				
				
				
				
				Bar:TweenSize(UDim2.new(0.027, 0, 0.735, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.01, true)
				
				
			end
			end
		end

end

Mouse.Idle:Connect(function()
	local Targ = Mouse.Target
	spawn(function()
		if Targ and Targ.Parent then
			if tostring(Targ.Parent) == "BlockField" and hold == true then
				OreFrame.Visible = false
				
				local distance = (Handle.CFrame.Position - Targ.CFrame.Position).Magnitude
				BoxDetermination(Targ, distance)
			else
				OreFrame.Visible = false
				BoxSelection.Adornee = nil
			end
		end
	end)
	
end)
Mouse.Button1Up:Connect(function()
	Mining = false
end)
Mouse.Button1Down:Connect(function()
	Mining = true
	TheChange = true
	spawn(function()
		while wait() do
			local Targ = Mouse.Target
			if  hold == true and Mining == true and Targ and Targ.Parent and tostring(Targ.Parent) == "BlockField" then
				RepeatMine(Targ)
			end
		end
	end)
	
	
end)
Tool.Equipped:Connect(function()
	hold = true
end)

Tool.Unequipped:Connect(function()
	hold = false
	OreFrame.Visible = false
end)
BoxSelection:GetPropertyChangedSignal("Adornee"):Connect(function(Thing)
	TheChange = true
	local Bar = OreFrame.Front.Bar
	
	if BoxSelection.Adornee == nil then
		return 
	else
		Time = tonumber(OreModule[tostring(BoxSelection.Adornee)]["Time"])
		print(Time)




		Bar:TweenSize(UDim2.new(0.027, 0, 0.735, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.01, true)
	end
	
end)


You aren’t really giving much insight into what is going on in your script so it’s somewhat hard to help. Anyways, let us assume you are using a raycast to detect which block is being mined. Therefore when you are clicking the sky, the raycast should return nil for an object target. You want to make a condition that accounts for the target being nil. If the target is nil, don’t animate the GUI at the bottom, or simply hide it. Whichever effect you want.

I try adding

if Target == nil then
			print("BRaey")
		end

But it wont work.

That isn’t printing anything because you are already filtering the target where you call it. When you say “if Targ” then it will not call RepeatMine(Targ) when it is nil. So you would need to print it where this filter is.

Ok so I tried printing it and each when I got the sky problem it just stopped printing. Is there a way I can make a condition if it doesnt print?

If you make this condition it should be printing “nil value” when you are hitting the sky.

		local Targ = Mouse.Target
		if  hold == true and Mining == true and Targ and Targ.Parent and tostring(Targ.Parent) == "BlockField" then
			RepeatMine(Targ)
		else
			print("nil value")
		end

I should clarify that this function is already in your Button1Down event. Simply add the else statement that I put

This most likely won’t work, but I might aswell try:

Basically add a value to each terrain piece and if it finds that value in the ore it pops the menu up, if not it ignores it.

Hopefully this helps!