I'm trying to make a pickaxe, It wont work, The SelectionBox isn't even active for some reason. I need my pickaxe to highlight over the blocks/ores. I have the script but it won't work. Please, someone help, this is urgent!


repeat wait() until script.Parent:FindFirstChild("Stats")

local Stats = require(script.Parent.Stats)

local diddy = true

local Mouse

local Equipped = false

local MobileMode = false

local Active = false

script.Parent.IsMining.Changed:connect(function()
	workspace.CurrentCamera.SelectedItem.Mining.Value = script.Parent.IsMining.Value
end)
workspace.CurrentCamera.SelectedItem.Mining.Value = script.Parent.IsMining.Value

local function Activate()
	if not Active then
		script.Parent.Activation:FireServer(true)
	--	workspace.CurrentCamera.SelectedItem.Mining.Value = true
		Active = true
		while Active do
			if workspace.CurrentCamera.SelectedItem.Value ~= nil then
	--			workspace.CurrentCamera.SelectedItem.Mining.Value = true
			else
				break			
			end
			wait(0.1)
		end
	--	workspace.CurrentCamera.SelectedItem.Mining.Value = false
	end
end
local function Deactivate()
	script.Parent.Activation:FireServer(false)
--	workspace.CurrentCamera.SelectedItem.Mining.Value = false
	Active = false	
end

local Selected = false

local function SelectOre(Ore)
	if Ore.Parent == workspace.Mine and (Ore.Position - script.Parent.Parent.Torso.Position).Magnitude <= (Stats.Range * 6) then
		workspace.CurrentCamera.SelectedItem.Value = Ore
		script.Parent.SetTarget:InvokeServer(Ore)
		Selected = true
	elseif Ore and Ore.Parent:FindFirstChild("PlacedItem") then
		workspace.CurrentCamera.SelectedItem.Value = Ore.Parent
		script.Parent.SetTarget:InvokeServer(Ore.Parent)
		Selected = true
	else
		workspace.CurrentCamera.SelectedItem.Value = nil
		script.Parent.SetTarget:InvokeServer(nil)		
		Selected = false	
	end
end

local function Unselect()
	workspace.CurrentCamera.SelectedItem.Value = nil
	script.Parent.SetTarget:InvokeServer(nil)
	Selected = false
end

local function GetOreFromScreen(X,Y)
	local OldRay = workspace.CurrentCamera:ViewportPointToRay(X,Y)
	local DaRay = Ray.new(OldRay.Origin,OldRay.Direction*100)
	local Ore = workspace:FindPartOnRayWithIgnoreList(DaRay,workspace.Players:GetChildren())
	return Ore
end

game:GetService("UserInputService").TouchTap:connect(function(posArray, Processed)
	if Equipped and #posArray == 1 --[[and not Processed ]] then
		MobileMode = true
		local Position = posArray[1]
		local Ore = GetOreFromScreen(Position.X,Position.Y)
		if Ore ~= nil then
			SelectOre(Ore)
		else
			Unselect()
		end
	end
end)

local TouchPosition

local function CheckFrame()
	if Active and MobileMode then
		local Ore = GetOreFromScreen(TouchPosition.X,TouchPosition.Y)
		SelectOre(Ore)		
	end
	local CurOre = workspace.CurrentCamera.SelectedItem.Value 
	if Selected and (CurOre.Parent == nil or CurOre == nil) then
		Unselect()
	end
end

local CamPro = Enum.RenderPriority.Camera.Value

if game:GetService("UserInputService").TouchEnabled then
	game:GetService("RunService"):BindToRenderStep("FrameCheck",CamPro+1,CheckFrame)
end

game:GetService("UserInputService").TouchLongPress:connect(function(posArray, State, Processed)
	if State == Enum.UserInputState.End or State == Enum.UserInputState.Cancel or not Equipped then
		Deactivate()
	elseif #posArray == 1 and State == Enum.UserInputState.Begin --[[and not Processed ]]then
		TouchPosition = posArray[1]
		MobileMode = true
		local Ore = GetOreFromScreen(TouchPosition.X,TouchPosition.Y)
		if Ore ~= nil then
			SelectOre(Ore)
			Activate()
		else
			Unselect()
			Deactivate()
		end
	elseif State == Enum.UserInputState.Change and Active then
		TouchPosition = posArray[1]		
	end
end)

local Mouse = game.Players.LocalPlayer:GetMouse()
Mouse.Button1Down:connect(function()
	if Equipped and (game:GetService("UserInputService").MouseEnabled or game:GetService("UserInputService").GamepadEnabled) then
		MobileMode = false
		Activate()
	end
end)
Mouse.Button1Up:connect(function()
	if Equipped and (game:GetService("UserInputService").MouseEnabled or game:GetService("UserInputService").GamepadEnabled) then
		MobileMode = false
		Deactivate()
	end
end)


script.Parent.Unequipped:connect(function()
	Equipped = false
	Mouse.TargetFilter = nil
	Deactivate()
	Unselect()
end)

script.Parent.Equipped:connect(function(Mousee)
	Equipped = true
	Mouse = Mousee
	Mouse = game.Players.LocalPlayer:GetMouse()
	if diddy then
		diddy = false
		game.Players.LocalPlayer.Character.ChildAdded:connect(function(Child)
			if Child.Name == "Platform" then
				Child.CanCollide = true
			end
		end)
	end
	Mouse.TargetFilter = workspace.Players
	while script.Parent.Enabled and script.Parent.Parent:FindFirstChild("Humanoid") do
		local Ore
		if not workspace.CurrentCamera.Full.Value then
			if game:GetService("UserInputService").GamepadEnabled then
				local OldRay
				if game:GetService("UserInputService").MouseBehavior == Enum.MouseBehavior.LockCenter then
					OldRay = workspace.CurrentCamera:ViewportPointToRay(workspace.CurrentCamera.ViewportSize.X/2,workspace.CurrentCamera.ViewportSize.Y/2)
				else
					OldRay = workspace.CurrentCamera:ViewportPointToRay(workspace.CurrentCamera.ViewportSize.X/2,workspace.CurrentCamera.ViewportSize.Y/2.8)
				end
				local DaRay = Ray.new(OldRay.Origin,OldRay.Direction*100)
				Ore = workspace:FindPartOnRayWithIgnoreList(DaRay,workspace.Players:GetChildren())
			elseif game:GetService("UserInputService").MouseEnabled then
				Ore = Mouse.Target
			end
			if Ore then
				SelectOre(Ore)
			elseif not MobileMode then
				workspace.CurrentCamera.SelectedItem.Value = nil
				
			--	script.Parent.Target.Value = nil
				script.Parent.SetTarget:InvokeServer(nil)
			end
		elseif not MobileMode then
			workspace.CurrentCamera.SelectedItem.Value = nil
			script.Parent.SetTarget:InvokeServer(nil)
		end
		wait()
	end
	workspace.CurrentCamera.SelectedItem.Value = nil
	-- script.Parent.Target.Value = nil
	script.Parent.SetTarget:InvokeServer(nil)
end)