Mobile touch being delayed by one

I am making a tds, the mobile raycasting somehow gets delayed by one. What occurs is the first 2 clicks work fine but then after you would need to click twice to register clicking the part but once you click off the part then it would say it clicked the part then the next click registers the last part you clicked
Code:

ui_service.InputBegan:Connect(function(input, success)
	if success then return end
	if tower_tospawn then
		local position = findposition({workspace:GetDescendants()})
		if input.UserInputType == Enum.UserInputType.MouseButton1 then
			if position.Instance.CollisionGroup ~= "Parts" and position.Instance.CollisionGroup ~= "Default" and position.Instance.Name ~= "Hitbox" and tower_tospawn then
				repeat task.wait() until game.ReplicatedStorage.AllTowers:WaitForChild(tower_tospawn.Name)
				if player_cash >= tower_tospawn:FindFirstChild("Cost").Value then
					--local y = tower_tospawn:WaitForChild("HumanoidRootPart").Position.Y-tower_tospawn:WaitForChild("HumanoidRootPart").Size.Y/1.5+position.Instance.Size.Y/8
					local y = position.Position.Y + tower_tospawn["Left Leg"].Size.Y + (tower_tospawn.PrimaryPart.Size.Y/2)
					new_tower:FireServer(tower_tospawn.Name, CFrame.new(tower_tospawn.HumanoidRootPart.Position.X, y, tower_tospawn.HumanoidRootPart.Position.Z)*CFrame.fromOrientation(0, math.rad(rotation), 0))
					placetower_sound:Play()
					add_rangepart(tower_tospawn, false)
					toggletower_selection(true)
				else
					cantafford_sound:Play()
				end
				canceltower()
				remove_rangepart(false)
			end
		elseif input.UserInputType == Enum.UserInputType.Touch then
			local current_touch = tick() - last_touch
			if current_touch <= 0.2 then
				if position.Instance.CollisionGroup ~= "Parts" and position.Instance.CollisionGroup ~= "Default" and position.Instance.Name ~= "Hitbox" and tower_tospawn then
					repeat task.wait() until game.ReplicatedStorage.AllTowers:WaitForChild(tower_tospawn.Name)
					if player_cash >= tower_tospawn:FindFirstChild("Cost").Value then
						add_rangepart(tower_tospawn, false)
						--local y = tower_tospawn:WaitForChild("HumanoidRootPart").Position.Y-tower_tospawn:WaitForChild("HumanoidRootPart").Size.Y/1.5+position.Instance.Size.Y/8
						local y = position.Position.Y + tower_tospawn["Left Leg"].Size.Y + (tower_tospawn.PrimaryPart.Size.Y/2)
						new_tower:FireServer(tower_tospawn.Name, CFrame.new(tower_tospawn.HumanoidRootPart.Position.X, y, tower_tospawn.HumanoidRootPart.Position.Z)*CFrame.fromOrientation(0, math.rad(rotation), 0))
						placetower_sound:Play()
						toggletower_selection(true)
					else
						cantafford_sound:Play()
					end
				end
				canceltower()
				remove_rangepart(false)
			end
			last_touch = tick()
		elseif input.KeyCode == Enum.KeyCode.E and tower_tospawn then
			local tower_humanoidrootpart = tower_tospawn:WaitForChild("HumanoidRootPart")
			rotation += 90
			rotate_sound:Play()
		elseif input.KeyCode == Enum.KeyCode.X and tower_tospawn then
			canceltower()
			remove_rangepart(false)
			cancel_sound:Play()
		end
	elseif (input.UserInputType == Enum.UserInputType.Touch or input.UserInputType == Enum.UserInputType.MouseButton1) then
		if select_instance then
			toggletower_selection(false)
			remove_rangepart(true)
			local model = select_instance:FindFirstAncestorOfClass("Model")
			if model and model.Parent == workspace.Map.Towers then
				selected_tower = select_instance.Parent
				task.spawn(toggletower_selection, true)
				task.spawn(add_rangepart, selected_tower)
			else
				task.spawn(toggletower_selection, false)
				task.spawn(remove_rangepart)
				selected_tower = nil
			end
		else
			selected_tower = nil
			task.spawn(toggletower_selection, false)
			if selected_tower then
				task.spawn(remove_rangepart)
			end
		end
	end
end)